Previous 199869 Revisions Next

r20520 Saturday 26th January, 2013 at 23:18:19 UTC by Ryan Holtz
[CDI] Modernize MCD212 device. [MooglyGuy]
[src/mame/drivers]cdi.c
[src/mame/includes]cdi.h
[src/mame/machine]cdicdic.h
[src/mame/video]mcd212.c mcd212.h

trunk/src/mame/drivers/cdi.c
r20519r20520
6767   //AM_RANGE(0x00318000, 0x0031ffff) AM_NOP
6868   AM_RANGE(0x00320000, 0x00323fff) AM_DEVREADWRITE8_LEGACY("mk48t08", timekeeper_r, timekeeper_w, 0xff00)    /* nvram (only low bytes used) */
6969   AM_RANGE(0x00400000, 0x0047ffff) AM_ROM AM_REGION("maincpu", 0)
70   AM_RANGE(0x004fffe0, 0x004fffff) AM_READWRITE_LEGACY(mcd212_r, mcd212_w)
70   AM_RANGE(0x004fffe0, 0x004fffff) AM_DEVREADWRITE("mcd212", mcd212_device, regs_r, regs_w)
7171   //AM_RANGE(0x00500000, 0x0057ffff) AM_RAM
7272   AM_RANGE(0x00500000, 0x00ffffff) AM_NOP
7373   //AM_RANGE(0x00e00000, 0x00efffff) AM_RAM // DVC
r20519r20520
325325   MCFG_CPU_ADD("maincpu", SCC68070, CLOCK_A/2)
326326   MCFG_CPU_PROGRAM_MAP(cdimono1_mem)
327327
328   MCFG_MCD212_ADD("mcd212")
328329   MCFG_SCREEN_ADD("screen", RASTER)
329330   MCFG_SCREEN_REFRESH_RATE(60)
330331   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
trunk/src/mame/machine/cdicdic.h
r20519r20520
6969   // device-level overrides
7070   virtual void device_start();
7171   virtual void device_reset();
72   virtual void device_post_load() { }
73   virtual void device_clock_changed() { }
7472
7573   // internal callbacks
7674   TIMER_CALLBACK_MEMBER( audio_sample_trigger );
r20519r20520
119117   void decode_audio_sector(const UINT8 *xa, INT32 triggered);
120118};
121119
122
123120// device type definition
124121extern const device_type MACHINE_CDICDIC;
125122
trunk/src/mame/video/mcd212.c
r20519r20520
2424#include "video/mcd212.h"
2525#include "includes/cdi.h"
2626
27// device type definition
28const device_type MACHINE_MCD212 = &device_creator<mcd212_device>;
29
2730#if ENABLE_VERBOSE_LOG
2831INLINE void verboselog(running_machine &machine, int n_level, const char *s_fmt, ...)
2932{
r20519r20520
4144#define verboselog(x,y,z,...)
4245#endif
4346
44static void cdi220_draw_lcd(running_machine &machine, int y);
45static void mcd212_update_region_arrays(mcd212_regs_t *mcd212);
46static void mcd212_set_display_parameters(mcd212_regs_t *mcd212, int channel, UINT8 value);
47static void mcd212_update_visible_area(running_machine &machine);
48static void mcd212_set_vsr(mcd212_regs_t *mcd212, int channel, UINT32 value);
49static void mcd212_set_dcp(mcd212_regs_t *mcd212, int channel, UINT32 value);
50static UINT32 mcd212_get_vsr(mcd212_regs_t *mcd212, int channel);
51static UINT32 mcd212_get_dcp(mcd212_regs_t *mcd212, int channel);
52static UINT32 mcd212_get_screen_width(mcd212_regs_t *mcd212);
53static void mcd212_set_register(running_machine &machine, int channel, UINT8 reg, UINT32 value);
54static void mcd212_process_ica(mcd212_regs_t *mcd212, int channel);
55static void mcd212_process_dca(mcd212_regs_t *mcd212, int channel);
56static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels_r, UINT8 *pixels_g, UINT8 *pixels_b);
57static void mcd212_mix_lines(mcd212_regs_t *mcd212, UINT8 *plane_a_r, UINT8 *plane_a_g, UINT8 *plane_a_b, UINT8 *plane_b_r, UINT8 *plane_b_g, UINT8 *plane_b_b, UINT32 *out);
58static void mcd212_draw_cursor(mcd212_regs_t *mcd212, UINT32 *scanline, int y);
59static void mcd212_draw_scanline(mcd212_regs_t *mcd212, int y);
60
6147static const UINT16 cdi220_lcd_char[20*22] =
6248{
6349   0x2000, 0x2000, 0x2000, 0x2000, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0200, 0x0200, 0x0200, 0x0200,
r20519r20520
8470   0x1000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0400, 0x0400, 0x0400, 0x0400
8571};
8672
87static void cdi220_draw_lcd(running_machine &machine, int y)
73void mcd212_device::draw_lcd(int y)
8874{
89   cdi_state *state = machine.driver_data<cdi_state>();
75   cdi_state *state = machine().driver_data<cdi_state>();
9076   bitmap_rgb32 &bitmap = state->m_lcdbitmap;
9177   UINT32 *scanline = &bitmap.pix32(y);
9278   int x = 0;
r20519r20520
9480
9581   for(lcd = 0; lcd < 8; lcd++)
9682   {
97      cdislave_device *slave = downcast<cdislave_device *>(machine.device("slave"));
98      UINT16 data = (slave->get_lcd_state()[lcd*2] << 8) |
99                  slave->get_lcd_state()[lcd*2 + 1];
83      UINT16 data = (state->m_slave->get_lcd_state()[lcd*2] << 8) |
84                  state->m_slave->get_lcd_state()[lcd*2 + 1];
10085      for(x = 0; x < 20; x++)
10186      {
10287         if(data & cdi220_lcd_char[y*20 + x])
r20519r20520
11196   }
11297}
11398
114static void mcd212_update_region_arrays(mcd212_regs_t *mcd212)
99void mcd212_device::update_region_arrays()
115100{
116   int x = 0;
117101   int latched_rf0 = 0;
118102   int latched_rf1 = 0;
119   int latched_wfa = mcd212->channel[0].weight_factor_a[0];
120   int latched_wfb = mcd212->channel[1].weight_factor_b[0];
103   int latched_wfa = m_channel[0].weight_factor_a[0];
104   int latched_wfb = m_channel[1].weight_factor_b[0];
121105   int reg = 0;
122106
123   for(x = 0; x < 768; x++)
107   for(int x = 0; x < 768; x++)
124108   {
125      if(mcd212->channel[0].image_coding_method & MCD212_ICM_NR)
109      if(m_channel[0].image_coding_method & MCD212_ICM_NR)
126110      {
127         int reg_ = 0;
128         int flag = 0;
129
130         for(flag = 0; flag < 2; flag++)
111         for(int flag = 0; flag < 2; flag++)
131112         {
132            for(reg_ = 0; reg_ < 4; reg_++)
113            for(int reg_ = 0; reg_ < 4; reg_++)
133114            {
134               if(mcd212->channel[0].region_control[reg_] == 0)
115               if(m_channel[0].region_control[reg_] == 0)
135116               {
136117                  break;
137118               }
138               if(x == (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_X))
119               if(x == (m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_X))
139120               {
140                  switch((mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_OP) >> MCD212_RC_OP_SHIFT)
121                  switch((m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_OP) >> MCD212_RC_OP_SHIFT)
141122                  {
142123                     case 0: // End of region control for line
143124                        break;
r20519r20520
146127                     case 3: // Not used
147128                        break;
148129                     case 4: // Change weight of plane A
149                        latched_wfa = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
130                        latched_wfa = (m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
150131                        break;
151132                     case 5: // Not used
152133                        break;
153134                     case 6: // Change weight of plane B
154                        latched_wfb = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
135                        latched_wfb = (m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
155136                        break;
156137                     case 7: // Not used
157138                        break;
r20519r20520
179160                     case 11:    // Not used
180161                        break;
181162                     case 12: // Reset region flag and change weight of plane A
182                        latched_wfa = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
163                        latched_wfa = (m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
183164                        if(flag)
184165                        {
185166                           latched_rf1 = 0;
r20519r20520
190171                        }
191172                        break;
192173                     case 13: // Set region flag and change weight of plane A
193                        latched_wfa = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
174                        latched_wfa = (m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
194175                        if(flag)
195176                        {
196177                           latched_rf1 = 1;
r20519r20520
201182                        }
202183                        break;
203184                     case 14: // Reset region flag and change weight of plane B
204                        latched_wfb = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
185                        latched_wfb = (m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
205186                        if(flag)
206187                        {
207188                           latched_rf1 = 0;
r20519r20520
212193                        }
213194                        break;
214195                     case 15: // Set region flag and change weight of plane B
215                        latched_wfb = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
196                        latched_wfb = (m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
216197                        if(flag)
217198                        {
218199                           latched_rf1 = 1;
r20519r20520
231212      {
232213         if(reg < 8)
233214         {
234            int flag = (mcd212->channel[0].region_control[reg] & MCD212_RC_RF) >> MCD212_RC_RF_SHIFT;
235            if(!(mcd212->channel[0].region_control[reg] & MCD212_RC_OP))
215            int flag = (m_channel[0].region_control[reg] & MCD212_RC_RF) >> MCD212_RC_RF_SHIFT;
216            if(!(m_channel[0].region_control[reg] & MCD212_RC_OP))
236217            {
237218               for(; x < 768; x++)
238219               {
239                  mcd212->channel[0].weight_factor_a[x] = latched_wfa;
240                  mcd212->channel[1].weight_factor_b[x] = latched_wfb;
241                  mcd212->region_flag_0[x] = latched_rf0;
242                  mcd212->region_flag_1[x] = latched_rf1;
220                  m_channel[0].weight_factor_a[x] = latched_wfa;
221                  m_channel[1].weight_factor_b[x] = latched_wfb;
222                  m_region_flag_0[x] = latched_rf0;
223                  m_region_flag_1[x] = latched_rf1;
243224               }
244225               break;
245226            }
246            if(x == (mcd212->channel[0].region_control[reg] & MCD212_RC_X))
227            if(x == (m_channel[0].region_control[reg] & MCD212_RC_X))
247228            {
248               switch((mcd212->channel[0].region_control[reg] & MCD212_RC_OP) >> MCD212_RC_OP_SHIFT)
229               switch((m_channel[0].region_control[reg] & MCD212_RC_OP) >> MCD212_RC_OP_SHIFT)
249230               {
250231                  case 0: // End of region control for line
251232                     break;
r20519r20520
254235                  case 3: // Not used
255236                     break;
256237                  case 4: // Change weight of plane A
257                     latched_wfa = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
238                     latched_wfa = (m_channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
258239                     break;
259240                  case 5: // Not used
260241                     break;
261242                  case 6: // Change weight of plane B
262                     latched_wfb = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
243                     latched_wfb = (m_channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
263244                     break;
264245                  case 7: // Not used
265246                     break;
r20519r20520
287268                  case 11:    // Not used
288269                     break;
289270                  case 12: // Reset region flag and change weight of plane A
290                     latched_wfa = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
271                     latched_wfa = (m_channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
291272                     if(flag)
292273                     {
293274                        latched_rf1 = 0;
r20519r20520
298279                     }
299280                     break;
300281                  case 13: // Set region flag and change weight of plane A
301                     latched_wfa = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
282                     latched_wfa = (m_channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
302283                     if(flag)
303284                     {
304285                        latched_rf1 = 1;
r20519r20520
309290                     }
310291                     break;
311292                  case 14: // Reset region flag and change weight of plane B
312                     latched_wfb = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
293                     latched_wfb = (m_channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
313294                     if(flag)
314295                     {
315296                        latched_rf1 = 0;
r20519r20520
320301                     }
321302                     break;
322303                  case 15: // Set region flag and change weight of plane B
323                     latched_wfb = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
304                     latched_wfb = (m_channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT;
324305                     if(flag)
325306                     {
326307                        latched_rf1 = 1;
r20519r20520
335316            }
336317         }
337318      }
338      mcd212->channel[0].weight_factor_a[x] = latched_wfa;
339      mcd212->channel[1].weight_factor_b[x] = latched_wfb;
340      mcd212->region_flag_0[x] = latched_rf0;
341      mcd212->region_flag_1[x] = latched_rf1;
319      m_channel[0].weight_factor_a[x] = latched_wfa;
320      m_channel[1].weight_factor_b[x] = latched_wfb;
321      m_region_flag_0[x] = latched_rf0;
322      m_region_flag_1[x] = latched_rf1;
342323   }
343324}
344325
345static void mcd212_set_vsr(mcd212_regs_t *mcd212, int channel, UINT32 value)
326void mcd212_device::set_vsr(int channel, UINT32 value)
346327{
347   mcd212->channel[channel].vsr = value & 0x0000ffff;
348   mcd212->channel[channel].dcr &= 0xffc0;
349   mcd212->channel[channel].dcr |= (value >> 16) & 0x003f;
328   m_channel[channel].vsr = value & 0x0000ffff;
329   m_channel[channel].dcr &= 0xffc0;
330   m_channel[channel].dcr |= (value >> 16) & 0x003f;
350331}
351332
352static void mcd212_set_register(running_machine &machine, int channel, UINT8 reg, UINT32 value)
333void mcd212_device::set_register(int channel, UINT8 reg, UINT32 value)
353334{
354   cdi_state *state = machine.driver_data<cdi_state>();
355   mcd212_regs_t *mcd212 = &state->m_mcd212_regs;
356
357335   switch(reg)
358336   {
359337      case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: // CLUT 0 - 63
r20519r20520
364342      case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf:
365343      case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
366344      case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf:
367         verboselog(machine, 11, "          %04xxxxx: %d: CLUT[%d] = %08x\n", channel * 0x20, channel, mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80), value );
368         mcd212->channel[0].clut_r[mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >> 16) & 0xfc;
369         mcd212->channel[0].clut_g[mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >>  8) & 0xfc;
370         mcd212->channel[0].clut_b[mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >>  0) & 0xfc;
345         verboselog(machine, 11, "          %04xxxxx: %d: CLUT[%d] = %08x\n", channel * 0x20, channel, m_channel[channel].clut_bank * 0x40 + (reg - 0x80), value );
346         m_channel[0].clut_r[m_channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >> 16) & 0xfc;
347         m_channel[0].clut_g[m_channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >>  8) & 0xfc;
348         m_channel[0].clut_b[m_channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >>  0) & 0xfc;
371349         break;
372350      case 0xc0: // Image Coding Method
373351         if(channel == 0)
374352         {
375353            verboselog(machine, 6, "          %04xxxxx: %d: Image Coding Method = %08x\n", channel * 0x20, channel, value );
376            mcd212->channel[channel].image_coding_method = value;
354            m_channel[channel].image_coding_method = value;
377355         }
378356         break;
379357      case 0xc1: // Transparency Control
380358         if(channel == 0)
381359         {
382360            verboselog(machine, 6, "          %04xxxxx: %d: Transparency Control = %08x\n", channel * 0x20, channel, value );
383            mcd212->channel[channel].transparency_control = value;
361            m_channel[channel].transparency_control = value;
384362         }
385363         break;
386364      case 0xc2: // Plane Order
387365         if(channel == 0)
388366         {
389367            verboselog(machine, 6, "          %04xxxxx: %d: Plane Order = %08x\n", channel * 0x20, channel, value & 7);
390            mcd212->channel[channel].plane_order = value & 0x00000007;
368            m_channel[channel].plane_order = value & 0x00000007;
391369         }
392370         break;
393371      case 0xc3: // CLUT Bank Register
394372         verboselog(machine, 6, "          %04xxxxx: %d: CLUT Bank Register = %08x\n", channel * 0x20, channel, value & 3);
395         mcd212->channel[channel].clut_bank = channel ? (2 | (value & 0x00000001)) : (value & 0x00000003);
373         m_channel[channel].clut_bank = channel ? (2 | (value & 0x00000001)) : (value & 0x00000003);
396374         break;
397375      case 0xc4: // Transparent Color A
398376         if(channel == 0)
399377         {
400378            verboselog(machine, 6, "          %04xxxxx: %d: Transparent Color A = %08x\n", channel * 0x20, channel, value );
401            mcd212->channel[channel].transparent_color_a = value & 0xfcfcfc;
379            m_channel[channel].transparent_color_a = value & 0xfcfcfc;
402380         }
403381         break;
404382      case 0xc6: // Transparent Color B
405383         if(channel == 1)
406384         {
407385            verboselog(machine, 6, "          %04xxxxx: %d: Transparent Color B = %08x\n", channel * 0x20, channel, value );
408            mcd212->channel[channel].transparent_color_b = value & 0xfcfcfc;
386            m_channel[channel].transparent_color_b = value & 0xfcfcfc;
409387         }
410388         break;
411389      case 0xc7: // Mask Color A
412390         if(channel == 0)
413391         {
414392            verboselog(machine, 6, "          %04xxxxx: %d: Mask Color A = %08x\n", channel * 0x20, channel, value );
415            mcd212->channel[channel].mask_color_a = value & 0xfcfcfc;
393            m_channel[channel].mask_color_a = value & 0xfcfcfc;
416394         }
417395         break;
418396      case 0xc9: // Mask Color B
419397         if(channel == 1)
420398         {
421399            verboselog(machine, 6, "          %04xxxxx: %d: Mask Color B = %08x\n", channel * 0x20, channel, value );
422            mcd212->channel[channel].mask_color_b = value & 0xfcfcfc;
400            m_channel[channel].mask_color_b = value & 0xfcfcfc;
423401         }
424402         break;
425403      case 0xca: // Delta YUV Absolute Start Value A
426404         if(channel == 0)
427405         {
428406            verboselog(machine, 6, "          %04xxxxx: %d: Delta YUV Absolute Start Value A = %08x\n", channel * 0x20, channel, value );
429            mcd212->channel[channel].dyuv_abs_start_a = value;
407            m_channel[channel].dyuv_abs_start_a = value;
430408         }
431409         break;
432410      case 0xcb: // Delta YUV Absolute Start Value B
433411         if(channel == 1)
434412         {
435413            verboselog(machine, 6, "          %04xxxxx: %d: Delta YUV Absolute Start Value B = %08x\n", channel * 0x20, channel, value );
436            mcd212->channel[channel].dyuv_abs_start_b = value;
414            m_channel[channel].dyuv_abs_start_b = value;
437415         }
438416         break;
439417      case 0xcd: // Cursor Position
440418         if(channel == 0)
441419         {
442420            verboselog(machine, 6, "          %04xxxxx: %d: Cursor Position = %08x\n", channel * 0x20, channel, value );
443            mcd212->channel[channel].cursor_position = value;
421            m_channel[channel].cursor_position = value;
444422         }
445423         break;
446424      case 0xce: // Cursor Control
447425         if(channel == 0)
448426         {
449427            verboselog(machine, 11, "          %04xxxxx: %d: Cursor Control = %08x\n", channel * 0x20, channel, value );
450            mcd212->channel[channel].cursor_control = value;
428            m_channel[channel].cursor_control = value;
451429         }
452430         break;
453431      case 0xcf: // Cursor Pattern
454432         if(channel == 0)
455433         {
456434            verboselog(machine, 11, "          %04xxxxx: %d: Cursor Pattern[%d] = %04x\n", channel * 0x20, channel, (value >> 16) & 0x000f, value & 0x0000ffff);
457            mcd212->channel[channel].cursor_pattern[(value >> 16) & 0x000f] = value & 0x0000ffff;
435            m_channel[channel].cursor_pattern[(value >> 16) & 0x000f] = value & 0x0000ffff;
458436         }
459437         break;
460438      case 0xd0: // Region Control 0-7
r20519r20520
466444      case 0xd6:
467445      case 0xd7:
468446         verboselog(machine, 6, "          %04xxxxx: %d: Region Control %d = %08x\n", channel * 0x20, channel, reg & 7, value );
469         mcd212->channel[0].region_control[reg & 7] = value;
470         mcd212_update_region_arrays(mcd212);
447         m_channel[0].region_control[reg & 7] = value;
448         update_region_arrays();
471449         break;
472450      case 0xd8: // Backdrop Color
473451         if(channel == 0)
474452         {
475453            verboselog(machine, 6, "          %04xxxxx: %d: Backdrop Color = %08x\n", channel * 0x20, channel, value );
476            mcd212->channel[channel].backdrop_color = value;
454            m_channel[channel].backdrop_color = value;
477455         }
478456         break;
479457      case 0xd9: // Mosaic Pixel Hold Factor A
480458         if(channel == 0)
481459         {
482460            verboselog(machine, 6, "          %04xxxxx: %d: Mosaic Pixel Hold Factor A = %08x\n", channel * 0x20, channel, value );
483            mcd212->channel[channel].mosaic_hold_a = value;
461            m_channel[channel].mosaic_hold_a = value;
484462         }
485463         break;
486464      case 0xda: // Mosaic Pixel Hold Factor B
487465         if(channel == 1)
488466         {
489467            verboselog(machine, 6, "          %04xxxxx: %d: Mosaic Pixel Hold Factor B = %08x\n", channel * 0x20, channel, value );
490            mcd212->channel[channel].mosaic_hold_b = value;
468            m_channel[channel].mosaic_hold_b = value;
491469         }
492470         break;
493471      case 0xdb: // Weight Factor A
494472         if(channel == 0)
495473         {
496474            verboselog(machine, 6, "          %04xxxxx: %d: Weight Factor A = %08x\n", channel * 0x20, channel, value );
497            memset(mcd212->channel[channel].weight_factor_a, value & 0x000000ff, 768);
498            mcd212_update_region_arrays(mcd212);
475            memset(m_channel[channel].weight_factor_a, value & 0x000000ff, 768);
476            update_region_arrays();
499477         }
500478         break;
501479      case 0xdc: // Weight Factor B
502480         if(channel == 1)
503481         {
504482            verboselog(machine, 6, "          %04xxxxx: %d: Weight Factor B = %08x\n", channel * 0x20, channel, value );
505            memset(mcd212->channel[channel].weight_factor_b, value & 0x000000ff, 768);
506            mcd212_update_region_arrays(mcd212);
483            memset(m_channel[channel].weight_factor_b, value & 0x000000ff, 768);
484            update_region_arrays();
507485         }
508486         break;
509487   }
510488}
511489
512static UINT32 mcd212_get_vsr(mcd212_regs_t *mcd212, int channel)
490UINT32 mcd212_device::get_vsr(int channel)
513491{
514   return ((mcd212->channel[channel].dcr & 0x3f) << 16) | mcd212->channel[channel].vsr;
492   return ((m_channel[channel].dcr & 0x3f) << 16) | m_channel[channel].vsr;
515493}
516494
517static void mcd212_set_dcp(mcd212_regs_t *mcd212, int channel, UINT32 value)
495void mcd212_device::set_dcp(int channel, UINT32 value)
518496{
519   mcd212->channel[channel].dcp = value & 0x0000ffff;
520   mcd212->channel[channel].ddr &= 0xffc0;
521   mcd212->channel[channel].ddr |= (value >> 16) & 0x003f;
497   m_channel[channel].dcp = value & 0x0000ffff;
498   m_channel[channel].ddr &= 0xffc0;
499   m_channel[channel].ddr |= (value >> 16) & 0x003f;
522500}
523501
524static UINT32 mcd212_get_dcp(mcd212_regs_t *mcd212, int channel)
502UINT32 mcd212_device::get_dcp(int channel)
525503{
526   return ((mcd212->channel[channel].ddr & 0x3f) << 16) | mcd212->channel[channel].dcp;
504   return ((m_channel[channel].ddr & 0x3f) << 16) | m_channel[channel].dcp;
527505}
528506
529static void mcd212_set_display_parameters(mcd212_regs_t *mcd212, int channel, UINT8 value)
507void mcd212_device::set_display_parameters(int channel, UINT8 value)
530508{
531   mcd212->channel[channel].ddr &= 0xf0ff;
532   mcd212->channel[channel].ddr |= (value & 0x0f) << 8;
533   mcd212->channel[channel].dcr &= 0xf7ff;
534   mcd212->channel[channel].dcr |= (value & 0x10) << 7;
509   m_channel[channel].ddr &= 0xf0ff;
510   m_channel[channel].ddr |= (value & 0x0f) << 8;
511   m_channel[channel].dcr &= 0xf7ff;
512   m_channel[channel].dcr |= (value & 0x10) << 7;
535513}
536514
537static void mcd212_update_visible_area(running_machine &machine)
515void mcd212_device::update_visible_area()
538516{
539   cdi_state *state = machine.driver_data<cdi_state>();
540   mcd212_regs_t *mcd212 = &state->m_mcd212_regs;
541   const rectangle &visarea = machine.primary_screen->visible_area();
517   const rectangle &visarea = machine().primary_screen->visible_area();
542518   rectangle visarea1;
543   attoseconds_t period = machine.primary_screen->frame_period().attoseconds;
519   attoseconds_t period = machine().primary_screen->frame_period().attoseconds;
544520   int width = 0;
545521
546   if((mcd212->channel[0].dcr & (MCD212_DCR_CF | MCD212_DCR_FD)) && (mcd212->channel[0].csrw & MCD212_CSR1W_ST))
522   if((m_channel[0].dcr & (MCD212_DCR_CF | MCD212_DCR_FD)) && (m_channel[0].csrw & MCD212_CSR1W_ST))
547523   {
548524      width = 360;
549525   }
r20519r20520
557533   visarea1.min_y = visarea.min_y;
558534   visarea1.max_y = visarea.max_y;
559535
560   machine.primary_screen->configure(width, 302, visarea1, period);
536   machine().primary_screen->configure(width, 302, visarea1, period);
561537}
562538
563static UINT32 mcd212_get_screen_width(mcd212_regs_t *mcd212)
539UINT32 mcd212_device::get_screen_width()
564540{
565   if((mcd212->channel[0].dcr & (MCD212_DCR_CF | MCD212_DCR_FD)) && (mcd212->channel[0].csrw & MCD212_CSR1W_ST))
541   if((m_channel[0].dcr & (MCD212_DCR_CF | MCD212_DCR_FD)) && (m_channel[0].csrw & MCD212_CSR1W_ST))
566542   {
567543      return 720;
568544   }
569545   return 768;
570546}
571547
572static void mcd212_process_ica(mcd212_regs_t *mcd212, int channel)
548void mcd212_device::process_ica(int channel)
573549{
574   running_machine &machine = mcd212->machine();
575   cdi_state *state = machine.driver_data<cdi_state>();
550   cdi_state *state = machine().driver_data<cdi_state>();
576551   UINT16 *ica = channel ? state->m_planeb : state->m_planea;
577552   UINT32 addr = 0x000400/2;
578553   UINT32 cmd = 0;
r20519r20520
595570         case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: // RELOAD DCP
596571         case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
597572            verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD DCP\n", addr * 2 + channel * 0x200000, cmd, channel );
598            mcd212_set_dcp(mcd212, channel, cmd & 0x001fffff);
573            set_dcp(channel, cmd & 0x001fffff);
599574            break;
600575         case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: // RELOAD DCP and STOP
601576         case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f:
602577            verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD DCP and STOP\n", addr * 2 + channel * 0x200000, cmd, channel );
603            mcd212_set_dcp(mcd212, channel, cmd & 0x001fffff);
578            set_dcp(channel, cmd & 0x001fffff);
604579            stop = 1;
605580            break;
606581         case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: // RELOAD ICA
r20519r20520
611586         case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: // RELOAD VSR and STOP
612587         case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f:
613588            verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD VSR and STOP\n", addr * 2 + channel * 0x200000, cmd, channel );
614            mcd212_set_vsr(mcd212, channel, cmd & 0x001fffff);
589            set_vsr(channel, cmd & 0x001fffff);
615590            stop = 1;
616591            break;
617592         case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: // INTERRUPT
618593         case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f:
619594            verboselog(machine, 11, "%08x: %08x: ICA %d: INTERRUPT\n", addr * 2 + channel * 0x200000, cmd, channel );
620            mcd212->channel[1].csrr |= 1 << (2 - channel);
621            if(mcd212->channel[1].csrr & (MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2))
595            m_channel[1].csrr |= 1 << (2 - channel);
596            if(m_channel[1].csrr & (MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2))
622597            {
623598               UINT8 interrupt = (state->m_scc->get_lir() >> 4) & 7;
624599               if(interrupt)
r20519r20520
628603               }
629604            }
630605#if 0
631            if(mcd212->channel[1].csrr & MCD212_CSR2R_IT2)
606            if(m_channel[1].csrr & MCD212_CSR2R_IT2)
632607            {
633608               UINT8 interrupt = state->m_scc68070_regs.lir & 7;
634609               if(interrupt)
r20519r20520
641616            break;
642617         case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: // RELOAD DISPLAY PARAMETERS
643618            verboselog(machine, 6, "%08x: %08x: ICA %d: RELOAD DISPLAY PARAMETERS\n", addr * 2 + channel * 0x200000, cmd, channel );
644            mcd212_set_display_parameters(mcd212, channel, cmd & 0x1f);
619            set_display_parameters(channel, cmd & 0x1f);
645620            break;
646621         default:
647            mcd212_set_register(machine, channel, cmd >> 24, cmd & 0x00ffffff);
622            set_register(channel, cmd >> 24, cmd & 0x00ffffff);
648623            break;
649624      }
650625      if(stop)
r20519r20520
654629   }
655630}
656631
657static void mcd212_process_dca(mcd212_regs_t *mcd212, int channel)
632void mcd212_device::process_dca(int channel)
658633{
659   running_machine &machine = mcd212->machine();
660   cdi_state *state = machine.driver_data<cdi_state>();
634   cdi_state *state = machine().driver_data<cdi_state>();
661635   UINT16 *dca = channel ? state->m_planeb : state->m_planea;
662   UINT32 addr = (mcd212->channel[channel].dca & 0x0007ffff) / 2; //(mcd212_get_dcp(mcd212, channel) & 0x0007ffff) / 2; // mcd212->channel[channel].dca / 2;
636   UINT32 addr = (m_channel[channel].dca & 0x0007ffff) / 2; //(get_dcp(mcd212, channel) & 0x0007ffff) / 2; // m_channel[channel].dca / 2;
663637   UINT32 cmd = 0;
664638   UINT32 count = 0;
665639   UINT32 max = 64;
r20519r20520
689663         case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: // RELOAD DCP and STOP
690664         case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f:
691665            verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD DCP and STOP\n", addr * 2 + channel * 0x200000, cmd, channel );
692            mcd212_set_dcp(&state->m_mcd212_regs, channel, cmd & 0x001fffff);
666            set_dcp(channel, cmd & 0x001fffff);
693667            addr = (cmd & 0x0007ffff) / 2;
694668            addr_changed = 1;
695669            stop = 1;
r20519r20520
697671         case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: // RELOAD VSR
698672         case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f:
699673            verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD VSR\n", addr * 2 + channel * 0x200000, cmd, channel );
700            mcd212_set_vsr(&state->m_mcd212_regs, channel, cmd & 0x001fffff);
674            set_vsr(channel, cmd & 0x001fffff);
701675            break;
702676         case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: // RELOAD VSR and STOP
703677         case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f:
704678            verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD VSR and STOP\n", addr * 2 + channel * 0x200000, cmd, channel );
705            mcd212_set_vsr(&state->m_mcd212_regs, channel, cmd & 0x001fffff);
679            set_vsr(channel, cmd & 0x001fffff);
706680            stop = 1;
707681            break;
708682         case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: // INTERRUPT
709683         case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f:
710684            verboselog(machine, 11, "%08x: %08x: DCA %d: INTERRUPT\n", addr * 2 + channel * 0x200000, cmd, channel );
711            mcd212->channel[1].csrr |= 1 << (2 - channel);
712            if(mcd212->channel[1].csrr & (MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2))
685            m_channel[1].csrr |= 1 << (2 - channel);
686            if(m_channel[1].csrr & (MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2))
713687            {
714688               UINT8 interrupt = (state->m_scc->get_lir() >> 4) & 7;
715689               if(interrupt)
r20519r20520
719693               }
720694            }
721695#if 0
722            if(mcd212->channel[1].csrr & MCD212_CSR2R_IT2)
696            if(m_channel[1].csrr & MCD212_CSR2R_IT2)
723697            {
724698               UINT8 interrupt = state->m_scc68070_regs.lir & 7;
725699               if(interrupt)
r20519r20520
732706            break;
733707         case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: // RELOAD DISPLAY PARAMETERS
734708            verboselog(machine, 6, "%08x: %08x: DCA %d: RELOAD DISPLAY PARAMETERS\n", addr * 2 + channel * 0x200000, cmd, channel );
735            mcd212_set_display_parameters(&state->m_mcd212_regs, channel, cmd & 0x1f);
709            set_display_parameters(channel, cmd & 0x1f);
736710            break;
737711         default:
738            mcd212_set_register(machine, channel, cmd >> 24, cmd & 0x00ffffff);
712            set_register(channel, cmd >> 24, cmd & 0x00ffffff);
739713            break;
740714      }
741715      if(stop != 0 || count == max)
r20519r20520
750724         addr += (max - count) >> 1;
751725      }
752726   }
753   mcd212->channel[channel].dca = addr * 2;
727   m_channel[channel].dca = addr * 2;
754728}
755729
756730INLINE UINT8 MCD212_LIM(INT32 in)
r20519r20520
802776   return 0;
803777}
804778
805static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels_r, UINT8 *pixels_g, UINT8 *pixels_b)
779void mcd212_device::process_vsr(int channel, UINT8 *pixels_r, UINT8 *pixels_g, UINT8 *pixels_b)
806780{
807   running_machine &machine = mcd212->machine();
808   cdi_state *state = machine.driver_data<cdi_state>();
781   cdi_state *state = machine().driver_data<cdi_state>();
809782   UINT8 *data = reinterpret_cast<UINT8 *>(channel ? state->m_planeb.target() : state->m_planea.target());
810   UINT32 vsr = mcd212_get_vsr(mcd212, channel) & 0x0007ffff;
783   UINT32 vsr = get_vsr(channel) & 0x0007ffff;
811784   UINT8 done = 0;
812785   UINT32 x = 0;
813786   UINT32 icm_mask = channel ? MCD212_ICM_MODE2 : MCD212_ICM_MODE1;
814787   UINT32 icm_shift = channel ? MCD212_ICM_MODE2_SHIFT : MCD212_ICM_MODE1_SHIFT;
815   UINT8 icm = (mcd212->channel[0].image_coding_method & icm_mask) >> icm_shift;
816   UINT8 *clut_r = mcd212->channel[0].clut_r;
817   UINT8 *clut_g = mcd212->channel[0].clut_g;
818   UINT8 *clut_b = mcd212->channel[0].clut_b;
819   UINT8 mosaic_enable = ((mcd212->channel[channel].ddr & MCD212_DDR_FT) == MCD212_DDR_FT_MOSAIC);
820   UINT8 mosaic_factor = 1 << (((mcd212->channel[channel].ddr & MCD212_DDR_MT) >> MCD212_DDR_MT_SHIFT) + 1);
788   UINT8 icm = (m_channel[0].image_coding_method & icm_mask) >> icm_shift;
789   UINT8 *clut_r = m_channel[0].clut_r;
790   UINT8 *clut_g = m_channel[0].clut_g;
791   UINT8 *clut_b = m_channel[0].clut_b;
792   UINT8 mosaic_enable = ((m_channel[channel].ddr & MCD212_DDR_FT) == MCD212_DDR_FT_MOSAIC);
793   UINT8 mosaic_factor = 1 << (((m_channel[channel].ddr & MCD212_DDR_MT) >> MCD212_DDR_MT_SHIFT) + 1);
821794   int mosaic_index = 0;
822   UINT32 width = mcd212_get_screen_width(mcd212);
795   UINT32 width = get_screen_width();
823796
824797   //printf( "vsr before: %08x: ", vsr );
825798   //fflush(stdout);
r20519r20520
836809   {
837810      UINT8 byte = data[(vsr & 0x0007ffff) ^ 1];
838811      vsr++;
839      switch(mcd212->channel[channel].ddr & MCD212_DDR_FT)
812      switch(m_channel[channel].ddr & MCD212_DDR_FT)
840813      {
841814         case MCD212_DDR_FT_BMP:
842815         case MCD212_DDR_FT_BMP2:
843816         case MCD212_DDR_FT_MOSAIC:
844            if(mcd212->channel[channel].dcr & MCD212_DCR_CM)
817            if(m_channel[channel].dcr & MCD212_DCR_CM)
845818            {
846819               // 4-bit Bitmap
847820               verboselog(machine, 0, "Unsupported display mode: 4-bit Bitmap\n" );
r20519r20520
857830                  switch(channel)
858831                  {
859832                     case 0:
860                        bY = (mcd212->channel[0].dyuv_abs_start_a >> 16) & 0x000000ff;
861                        bU = (mcd212->channel[0].dyuv_abs_start_a >>  8) & 0x000000ff;
862                        bV = (mcd212->channel[0].dyuv_abs_start_a >>  0) & 0x000000ff;
833                        bY = (m_channel[0].dyuv_abs_start_a >> 16) & 0x000000ff;
834                        bU = (m_channel[0].dyuv_abs_start_a >>  8) & 0x000000ff;
835                        bV = (m_channel[0].dyuv_abs_start_a >>  0) & 0x000000ff;
863836                        break;
864837                     case 1:
865                        bY = (mcd212->channel[1].dyuv_abs_start_b >> 16) & 0x000000ff;
866                        bU = (mcd212->channel[1].dyuv_abs_start_b >>  8) & 0x000000ff;
867                        bV = (mcd212->channel[1].dyuv_abs_start_b >>  0) & 0x000000ff;
838                        bY = (m_channel[1].dyuv_abs_start_b >> 16) & 0x000000ff;
839                        bU = (m_channel[1].dyuv_abs_start_b >>  8) & 0x000000ff;
840                        bV = (m_channel[1].dyuv_abs_start_b >>  0) & 0x000000ff;
868841                        break;
869842                     default:
870843                        bY = bU = bV = 0x80;
r20519r20520
873846                  for(; x < width; x += 2)
874847                  {
875848                     BYTE68K b0 = byte;
876                     BYTE68K bU1 = bU + state->m_mcd212_ab.deltaUV[b0];
877                     BYTE68K bY0 = bY + state->m_mcd212_ab.deltaY[b0];
849                     BYTE68K bU1 = bU + m_ab.deltaUV[b0];
850                     BYTE68K bY0 = bY + m_ab.deltaY[b0];
878851
879852                     BYTE68K b1 = data[(vsr & 0x0007ffff) ^ 1];
880                     BYTE68K bV1 = bV + state->m_mcd212_ab.deltaUV[b1];
881                     BYTE68K bY1 = bY0 + state->m_mcd212_ab.deltaY[b1];
853                     BYTE68K bV1 = bV + m_ab.deltaUV[b1];
854                     BYTE68K bY1 = bY0 + m_ab.deltaY[b1];
882855
883856                     BYTE68K bU0 = (bU + bU1) >> 1;
884857                     BYTE68K bV0 = (bV + bV1) >> 1;
r20519r20520
891864                     bU = bU0;
892865                     bV = bV0;
893866
894                     pbLimit = state->m_mcd212_ab.limit + bY + BYTE68K_MAX;
867                     pbLimit = m_ab.limit + bY + BYTE68K_MAX;
895868
896                     pixels_r[x + 0] = pixels_r[x + 1] = pbLimit[state->m_mcd212_ab.matrixVR[bV]];
897                     pixels_g[x + 0] = pixels_g[x + 1] = pbLimit[state->m_mcd212_ab.matrixUG[bU] + state->m_mcd212_ab.matrixVG[bV]];
898                     pixels_b[x + 0] = pixels_b[x + 1] = pbLimit[state->m_mcd212_ab.matrixUB[bU]];
869                     pixels_r[x + 0] = pixels_r[x + 1] = pbLimit[m_ab.matrixVR[bV]];
870                     pixels_g[x + 0] = pixels_g[x + 1] = pbLimit[m_ab.matrixUG[bU] + m_ab.matrixVG[bV]];
871                     pixels_b[x + 0] = pixels_b[x + 1] = pbLimit[m_ab.matrixUB[bU]];
899872
900873                     if(mosaic_enable)
901874                     {
r20519r20520
919892                     bU = bU1;
920893                     bV = bV1;
921894
922                     pbLimit = state->m_mcd212_ab.limit + bY + BYTE68K_MAX;
895                     pbLimit = m_ab.limit + bY + BYTE68K_MAX;
923896
924                     pixels_r[x + 0] = pixels_r[x + 1] = pbLimit[state->m_mcd212_ab.matrixVR[bV]];
925                     pixels_g[x + 0] = pixels_g[x + 1] = pbLimit[state->m_mcd212_ab.matrixUG[bU] + state->m_mcd212_ab.matrixVG[bV]];
926                     pixels_b[x + 0] = pixels_b[x + 1] = pbLimit[state->m_mcd212_ab.matrixUB[bU]];
897                     pixels_r[x + 0] = pixels_r[x + 1] = pbLimit[m_ab.matrixVR[bV]];
898                     pixels_g[x + 0] = pixels_g[x + 1] = pbLimit[m_ab.matrixUG[bU] + m_ab.matrixVG[bV]];
899                     pixels_b[x + 0] = pixels_b[x + 1] = pbLimit[m_ab.matrixUB[bU]];
927900
928901                     if(mosaic_enable)
929902                     {
r20519r20520
943916
944917                     vsr++;
945918                  }
946                  mcd212_set_vsr(&state->m_mcd212_regs, channel, (vsr - 1) & 0x0007ffff);
919                  set_vsr(channel, (vsr - 1) & 0x0007ffff);
947920               }
948921               else if(icm == 1 || icm == 3 || icm == 4)
949922               {
r20519r20520
972945                     byte = data[(vsr & 0x0007ffff) ^ 1];
973946                     vsr++;
974947                  }
975                  mcd212_set_vsr(&state->m_mcd212_regs, channel, (vsr - 1) & 0x0007ffff);
948                  set_vsr(channel, (vsr - 1) & 0x0007ffff);
976949               }
977950               else if(icm == 11)
978951               {
r20519r20520
1008981                     byte = data[(vsr & 0x0007ffff) ^ 1];
1009982                     vsr++;
1010983                  }
1011                  mcd212_set_vsr(&state->m_mcd212_regs, channel, (vsr - 1) & 0x0007ffff);
984                  set_vsr(channel, (vsr - 1) & 0x0007ffff);
1012985               }
1013986               else
1014987               {
r20519r20520
1023996            done = 1;
1024997            break;
1025998         case MCD212_DDR_FT_RLE:
1026            if(mcd212->channel[channel].dcr & MCD212_DCR_CM)
999            if(m_channel[channel].dcr & MCD212_DCR_CM)
10271000            {
10281001               verboselog(machine, 0, "Unsupported display mode: 4-bit RLE\n" );
10291002               done = 1;
r20519r20520
10521025                        pixels_b[x] = b;
10531026                     }
10541027                     done = 1;
1055                     mcd212_set_vsr(&state->m_mcd212_regs, channel, vsr);
1028                     set_vsr(channel, vsr);
10561029                  }
10571030                  else
10581031                  {
r20519r20520
10741047                     if(x >= width)
10751048                     {
10761049                        done = 1;
1077                        mcd212_set_vsr(&state->m_mcd212_regs, channel, vsr);
1050                        set_vsr(channel, vsr);
10781051                     }
10791052                  }
10801053               }
r20519r20520
10931066                  if(x >= width)
10941067                  {
10951068                     done = 1;
1096                     mcd212_set_vsr(&state->m_mcd212_regs, channel, vsr);
1069                     set_vsr(channel, vsr);
10971070                  }
10981071               }
10991072            }
r20519r20520
11051078   //mcd212_set_vsr(&state->m_mcd212_regs, channel, vsr);
11061079}
11071080
1108static const UINT32 mcd212_4bpp_color[16] =
1081const UINT32 mcd212_device::s_4bpp_color[16] =
11091082{
11101083   0x00101010, 0x0010107a, 0x00107a10, 0x00107a7a, 0x007a1010, 0x007a107a, 0x007a7a10, 0x007a7a7a,
11111084   0x00101010, 0x001010e6, 0x0010e610, 0x0010e6e6, 0x00e61010, 0x00e610e6, 0x00e6e610, 0x00e6e6e6
11121085};
11131086
1114static void mcd212_mix_lines(mcd212_regs_t *mcd212, UINT8 *plane_a_r, UINT8 *plane_a_g, UINT8 *plane_a_b, UINT8 *plane_b_r, UINT8 *plane_b_g, UINT8 *plane_b_b, UINT32 *out)
1087void mcd212_device::mix_lines(UINT8 *plane_a_r, UINT8 *plane_a_g, UINT8 *plane_a_b, UINT8 *plane_b_r, UINT8 *plane_b_g, UINT8 *plane_b_b, UINT32 *out)
11151088{
1116   running_machine &machine = mcd212->machine();
1117   int x = 0;
1118   UINT8 debug_mode = machine.root_device().ioport("DEBUG")->read();
1089   UINT8 debug_mode = machine().root_device().ioport("DEBUG")->read();
11191090   UINT8 global_plane_a_disable = debug_mode & 1;
11201091   UINT8 global_plane_b_disable = debug_mode & 2;
11211092   UINT8 debug_backdrop_enable = debug_mode & 4;
11221093   UINT8 debug_backdrop_index = debug_mode >> 4;
1123   UINT32 backdrop = debug_backdrop_enable ? mcd212_4bpp_color[debug_backdrop_index] : mcd212_4bpp_color[mcd212->channel[0].backdrop_color];
1124   UINT8 transparency_mode_a = (mcd212->channel[0].transparency_control >> 0) & 0x0f;
1125   UINT8 transparency_mode_b = (mcd212->channel[0].transparency_control >> 8) & 0x0f;
1126   UINT8 transparent_color_a_r = (UINT8)(mcd212->channel[0].transparent_color_a >> 16);
1127   UINT8 transparent_color_a_g = (UINT8)(mcd212->channel[0].transparent_color_a >>  8);
1128   UINT8 transparent_color_a_b = (UINT8)(mcd212->channel[0].transparent_color_a >>  0);
1129   UINT8 transparent_color_b_r = (UINT8)(mcd212->channel[1].transparent_color_b >> 16);
1130   UINT8 transparent_color_b_g = (UINT8)(mcd212->channel[1].transparent_color_b >>  8);
1131   UINT8 transparent_color_b_b = (UINT8)(mcd212->channel[1].transparent_color_b >>  0);
1132   UINT8 image_coding_method_a = mcd212->channel[0].image_coding_method & 0x0000000f;
1133   UINT8 image_coding_method_b = (mcd212->channel[0].image_coding_method >> 8) & 0x0000000f;
1134   UINT8 dyuv_enable_a = (image_coding_method_a == 5);
1135   UINT8 dyuv_enable_b = (image_coding_method_b == 5);
1136   UINT8 mosaic_enable_a = (mcd212->channel[0].mosaic_hold_a & 0x800000) >> 23;
1137   UINT8 mosaic_enable_b = (mcd212->channel[1].mosaic_hold_b & 0x800000) >> 23;
1138   UINT8 mosaic_count_a = (mcd212->channel[0].mosaic_hold_a & 0x0000ff) << 1;
1139   UINT8 mosaic_count_b = (mcd212->channel[1].mosaic_hold_b & 0x0000ff) << 1;
1140   for(x = 0; x < 768; x++)
1094   UINT32 backdrop = debug_backdrop_enable ? s_4bpp_color[debug_backdrop_index] : s_4bpp_color[m_channel[0].backdrop_color];
1095   UINT8 transparency_mode_a = (m_channel[0].transparency_control >> 0) & 0x0f;
1096   UINT8 transparency_mode_b = (m_channel[0].transparency_control >> 8) & 0x0f;
1097   UINT8 transparent_color_a_r = (UINT8)(m_channel[0].transparent_color_a >> 16);
1098   UINT8 transparent_color_a_g = (UINT8)(m_channel[0].transparent_color_a >>  8);
1099   UINT8 transparent_color_a_b = (UINT8)(m_channel[0].transparent_color_a >>  0);
1100   UINT8 transparent_color_b_r = (UINT8)(m_channel[1].transparent_color_b >> 16);
1101   UINT8 transparent_color_b_g = (UINT8)(m_channel[1].transparent_color_b >>  8);
1102   UINT8 transparent_color_b_b = (UINT8)(m_channel[1].transparent_color_b >>  0);
1103   UINT8 image_coding_method_a = m_channel[0].image_coding_method & 0x0000000f;
1104   UINT8 image_coding_method_b = (m_channel[0].image_coding_method >> 8) & 0x0000000f;
1105   bool dyuv_enable_a = (image_coding_method_a == 5);
1106   bool dyuv_enable_b = (image_coding_method_b == 5);
1107   UINT8 mosaic_enable_a = (m_channel[0].mosaic_hold_a & 0x800000) >> 23;
1108   UINT8 mosaic_enable_b = (m_channel[1].mosaic_hold_b & 0x800000) >> 23;
1109   UINT8 mosaic_count_a = (m_channel[0].mosaic_hold_a & 0x0000ff) << 1;
1110   UINT8 mosaic_count_b = (m_channel[1].mosaic_hold_b & 0x0000ff) << 1;
1111   for(int x = 0; x < 768; x++)
11411112   {
11421113      out[x] = backdrop;
1143      if(!(mcd212->channel[0].transparency_control & MCD212_TCR_DISABLE_MX))
1114      if(!(m_channel[0].transparency_control & MCD212_TCR_DISABLE_MX))
11441115      {
1145         UINT8 abr = MCD212_LIM(((MCD212_LIM((INT32)plane_a_r[x] - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + ((MCD212_LIM((INT32)plane_b_r[x] - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16);
1146         UINT8 abg = MCD212_LIM(((MCD212_LIM((INT32)plane_a_g[x] - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + ((MCD212_LIM((INT32)plane_b_g[x] - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16);
1147         UINT8 abb = MCD212_LIM(((MCD212_LIM((INT32)plane_a_b[x] - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + ((MCD212_LIM((INT32)plane_b_b[x] - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16);
1116         UINT8 abr = MCD212_LIM(((MCD212_LIM((INT32)plane_a_r[x] - 16) * m_channel[0].weight_factor_a[x]) >> 6) + ((MCD212_LIM((INT32)plane_b_r[x] - 16) * m_channel[1].weight_factor_b[x]) >> 6) + 16);
1117         UINT8 abg = MCD212_LIM(((MCD212_LIM((INT32)plane_a_g[x] - 16) * m_channel[0].weight_factor_a[x]) >> 6) + ((MCD212_LIM((INT32)plane_b_g[x] - 16) * m_channel[1].weight_factor_b[x]) >> 6) + 16);
1118         UINT8 abb = MCD212_LIM(((MCD212_LIM((INT32)plane_a_b[x] - 16) * m_channel[0].weight_factor_a[x]) >> 6) + ((MCD212_LIM((INT32)plane_b_b[x] - 16) * m_channel[1].weight_factor_b[x]) >> 6) + 16);
11481119         out[x] = (abr << 16) | (abg << 8) | abb;
11491120      }
11501121      else
r20519r20520
11661137               plane_enable_a = (plane_a_r_cur != transparent_color_a_r || plane_a_g_cur != transparent_color_a_g || plane_a_b_cur != transparent_color_a_b);
11671138               break;
11681139            case 3:
1169               plane_enable_a = !mcd212->region_flag_0[x];
1140               plane_enable_a = !m_region_flag_0[x];
11701141               break;
11711142            case 4:
1172               plane_enable_a = !mcd212->region_flag_1[x];
1143               plane_enable_a = !m_region_flag_1[x];
11731144               break;
11741145            case 5:
1175               plane_enable_a = (plane_a_r_cur != transparent_color_a_r || plane_a_g_cur != transparent_color_a_g || plane_a_b_cur != transparent_color_a_b) && (dyuv_enable_a || mcd212->region_flag_0[x] == 0);
1146               plane_enable_a = (plane_a_r_cur != transparent_color_a_r || plane_a_g_cur != transparent_color_a_g || plane_a_b_cur != transparent_color_a_b) && (dyuv_enable_a || m_region_flag_0[x] == 0);
11761147               break;
11771148            case 6:
1178               plane_enable_a = (plane_a_r_cur != transparent_color_a_r || plane_a_g_cur != transparent_color_a_g || plane_a_b_cur != transparent_color_a_b) && (dyuv_enable_a || mcd212->region_flag_1[x] == 0);
1149               plane_enable_a = (plane_a_r_cur != transparent_color_a_r || plane_a_g_cur != transparent_color_a_g || plane_a_b_cur != transparent_color_a_b) && (dyuv_enable_a || m_region_flag_1[x] == 0);
11791150               break;
11801151            case 8:
11811152               plane_enable_a = 1;
r20519r20520
11841155               plane_enable_a = (plane_a_r_cur == transparent_color_a_r && plane_a_g_cur == transparent_color_a_g && plane_a_b_cur == transparent_color_a_b);
11851156               break;
11861157            case 11:
1187               plane_enable_a = mcd212->region_flag_0[x];
1158               plane_enable_a = m_region_flag_0[x];
11881159               break;
11891160            case 12:
1190               plane_enable_a = mcd212->region_flag_1[x];
1161               plane_enable_a = m_region_flag_1[x];
11911162               break;
11921163            case 13:
1193               plane_enable_a = (plane_a_r_cur == transparent_color_a_r && plane_a_g_cur == transparent_color_a_g && plane_a_b_cur == transparent_color_a_b) || dyuv_enable_a || mcd212->region_flag_0[x] == 1;
1164               plane_enable_a = (plane_a_r_cur == transparent_color_a_r && plane_a_g_cur == transparent_color_a_g && plane_a_b_cur == transparent_color_a_b) || dyuv_enable_a || m_region_flag_0[x] == 1;
11941165               break;
11951166            case 14:
1196               plane_enable_a = (plane_a_r_cur == transparent_color_a_r && plane_a_g_cur == transparent_color_a_g && plane_a_b_cur == transparent_color_a_b) || dyuv_enable_a || mcd212->region_flag_1[x] == 1;
1167               plane_enable_a = (plane_a_r_cur == transparent_color_a_r && plane_a_g_cur == transparent_color_a_g && plane_a_b_cur == transparent_color_a_b) || dyuv_enable_a || m_region_flag_1[x] == 1;
11971168               break;
11981169            default:
11991170               verboselog(machine, 0, "Unhandled transparency mode for plane A: %d\n", transparency_mode_a);
r20519r20520
12091180               plane_enable_b = (plane_b_r_cur != transparent_color_b_r || plane_b_g_cur != transparent_color_b_g || plane_b_b_cur != transparent_color_b_b);
12101181               break;
12111182            case 3:
1212               plane_enable_b = !mcd212->region_flag_0[x];
1183               plane_enable_b = !m_region_flag_0[x];
12131184               break;
12141185            case 4:
1215               plane_enable_b = !mcd212->region_flag_1[x];
1186               plane_enable_b = !m_region_flag_1[x];
12161187               break;
12171188            case 5:
1218               plane_enable_b = (plane_b_r_cur != transparent_color_b_r || plane_b_g_cur != transparent_color_b_g || plane_b_b_cur != transparent_color_b_b) && (dyuv_enable_b || mcd212->region_flag_0[x] == 0);
1189               plane_enable_b = (plane_b_r_cur != transparent_color_b_r || plane_b_g_cur != transparent_color_b_g || plane_b_b_cur != transparent_color_b_b) && (dyuv_enable_b || m_region_flag_0[x] == 0);
12191190               break;
12201191            case 6:
1221               plane_enable_b = (plane_b_r_cur != transparent_color_b_r || plane_b_g_cur != transparent_color_b_g || plane_b_b_cur != transparent_color_b_b) && (dyuv_enable_b || mcd212->region_flag_1[x] == 0);
1192               plane_enable_b = (plane_b_r_cur != transparent_color_b_r || plane_b_g_cur != transparent_color_b_g || plane_b_b_cur != transparent_color_b_b) && (dyuv_enable_b || m_region_flag_1[x] == 0);
12221193               break;
12231194            case 8:
12241195               plane_enable_b = 1;
r20519r20520
12271198               plane_enable_b = (plane_b_r_cur == transparent_color_b_r && plane_b_g_cur == transparent_color_b_g && plane_b_b_cur == transparent_color_b_b);
12281199               break;
12291200            case 11:
1230               plane_enable_b = mcd212->region_flag_0[x];
1201               plane_enable_b = m_region_flag_0[x];
12311202               break;
12321203            case 12:
1233               plane_enable_b = mcd212->region_flag_1[x];
1204               plane_enable_b = m_region_flag_1[x];
12341205               break;
12351206            case 13:
1236               plane_enable_b = (plane_b_r_cur == transparent_color_b_r && plane_b_g_cur == transparent_color_b_g && plane_b_b_cur == transparent_color_b_b) || dyuv_enable_b || mcd212->region_flag_0[x] == 1;
1207               plane_enable_b = (plane_b_r_cur == transparent_color_b_r && plane_b_g_cur == transparent_color_b_g && plane_b_b_cur == transparent_color_b_b) || dyuv_enable_b || m_region_flag_0[x] == 1;
12371208               break;
12381209            case 14:
1239               plane_enable_b = (plane_b_r_cur == transparent_color_b_r && plane_b_g_cur == transparent_color_b_g && plane_b_b_cur == transparent_color_b_b) || dyuv_enable_b || mcd212->region_flag_1[x] == 1;
1210               plane_enable_b = (plane_b_r_cur == transparent_color_b_r && plane_b_g_cur == transparent_color_b_g && plane_b_b_cur == transparent_color_b_b) || dyuv_enable_b || m_region_flag_1[x] == 1;
12401211               break;
12411212            default:
12421213               verboselog(machine, 0, "Unhandled transparency mode for plane B: %d\n", transparency_mode_b);
r20519r20520
12511222         {
12521223            plane_enable_b = 0;
12531224         }
1254         plane_a_r_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_r_cur - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + 16);
1255         plane_a_g_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_g_cur - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + 16);
1256         plane_a_b_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_b_cur - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + 16);
1257         plane_b_r_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_r_cur - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16);
1258         plane_b_g_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_g_cur - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16);
1259         plane_b_b_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_b_cur - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16);
1260         switch(mcd212->channel[0].plane_order)
1225         plane_a_r_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_r_cur - 16) * m_channel[0].weight_factor_a[x]) >> 6) + 16);
1226         plane_a_g_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_g_cur - 16) * m_channel[0].weight_factor_a[x]) >> 6) + 16);
1227         plane_a_b_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_b_cur - 16) * m_channel[0].weight_factor_a[x]) >> 6) + 16);
1228         plane_b_r_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_r_cur - 16) * m_channel[1].weight_factor_b[x]) >> 6) + 16);
1229         plane_b_g_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_g_cur - 16) * m_channel[1].weight_factor_b[x]) >> 6) + 16);
1230         plane_b_b_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_b_cur - 16) * m_channel[1].weight_factor_b[x]) >> 6) + 16);
1231         switch(m_channel[0].plane_order)
12611232         {
12621233            case MCD212_POR_AB:
12631234               if(plane_enable_a)
r20519r20520
12841255   }
12851256}
12861257
1287static void mcd212_draw_cursor(mcd212_regs_t *mcd212, UINT32 *scanline, int y)
1258void mcd212_device::draw_cursor(UINT32 *scanline, int y)
12881259{
1289   if(mcd212->channel[0].cursor_control & MCD212_CURCNT_EN)
1260   if(m_channel[0].cursor_control & MCD212_CURCNT_EN)
12901261   {
1291      UINT16 curx =  mcd212->channel[0].cursor_position        & 0x3ff;
1292      UINT16 cury = ((mcd212->channel[0].cursor_position >> 12) & 0x3ff) + 22;
1293      UINT32 x = 0;
1262      UINT16 curx =  m_channel[0].cursor_position        & 0x3ff;
1263      UINT16 cury = ((m_channel[0].cursor_position >> 12) & 0x3ff) + 22;
12941264      if(y >= cury && y < (cury + 16))
12951265      {
1296         UINT32 color = mcd212_4bpp_color[mcd212->channel[0].cursor_control & MCD212_CURCNT_COLOR];
1266         UINT32 color = s_4bpp_color[m_channel[0].cursor_control & MCD212_CURCNT_COLOR];
12971267         y -= cury;
1298         if(mcd212->channel[0].cursor_control & MCD212_CURCNT_CUW)
1268         if(m_channel[0].cursor_control & MCD212_CURCNT_CUW)
12991269         {
1300            for(x = curx; x < curx + 64 && x < 768; x++)
1270            for(int x = curx; x < curx + 64 && x < 768; x++)
13011271            {
1302               if(mcd212->channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 2))))
1272               if(m_channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 2))))
13031273               {
13041274                  scanline[(x++)/2] = color;
13051275                  scanline[(x++)/2] = color;
r20519r20520
13131283         }
13141284         else
13151285         {
1316            for(x = curx; x < curx + 32 && x < 768; x++)
1286            for(int x = curx; x < curx + 32 && x < 768; x++)
13171287            {
1318               if(mcd212->channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 1))))
1288               if(m_channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 1))))
13191289               {
13201290                  scanline[(x++)/2] = color;
13211291                  scanline[x/2] = color;
13221292               }
1323               else
1324               {
1325               }
13261293            }
13271294         }
13281295      }
13291296   }
13301297}
13311298
1332static void mcd212_draw_scanline(mcd212_regs_t *mcd212, int y)
1299void mcd212_device::draw_scanline(int y)
13331300{
1334   bitmap_rgb32 &bitmap = mcd212->m_bitmap;
13351301   UINT8 plane_a_r[768], plane_a_g[768], plane_a_b[768];
13361302   UINT8 plane_b_r[768], plane_b_g[768], plane_b_b[768];
13371303   UINT32 out[768];
1338   UINT32 *scanline = &bitmap.pix32(y);
1304   UINT32 *scanline = &m_bitmap.pix32(y);
13391305   int x;
13401306
1341   mcd212_process_vsr(mcd212, 0, plane_a_r, plane_a_g, plane_a_b);
1342   mcd212_process_vsr(mcd212, 1, plane_b_r, plane_b_g, plane_b_b);
1307   process_vsr(0, plane_a_r, plane_a_g, plane_a_b);
1308   process_vsr(1, plane_b_r, plane_b_g, plane_b_b);
13431309
1344   mcd212_mix_lines(mcd212, plane_a_r, plane_a_g, plane_a_b, plane_b_r, plane_b_g, plane_b_b, out);
1310   mix_lines(plane_a_r, plane_a_g, plane_a_b, plane_b_r, plane_b_g, plane_b_b, out);
13451311
13461312   for(x = 0; x < 384; x++)
13471313   {
13481314      scanline[x] = out[x*2];
13491315   }
13501316
1351   mcd212_draw_cursor(mcd212, scanline, y);
1317   draw_cursor(scanline, y);
13521318}
13531319
1354READ16_HANDLER( mcd212_r )
1320READ16_MEMBER( mcd212_device::regs_r )
13551321{
1356   cdi_state *state = space.machine().driver_data<cdi_state>();
1357   mcd212_regs_t *mcd212 = &state->m_mcd212_regs;
1322   cdi_state *state = machine().driver_data<cdi_state>();
13581323   UINT8 channel = 1 - (offset / 8);
13591324
13601325   switch(offset)
r20519r20520
13631328      case 0x10/2:
13641329         if(ACCESSING_BITS_0_7)
13651330         {
1366            verboselog(space.machine(), 12, "mcd212_r: Status Register %d: %02x & %04x\n", channel + 1, mcd212->channel[1 - (offset / 8)].csrr, mem_mask);
1331            verboselog(machine(), 12, "mcd212_r: Status Register %d: %02x & %04x\n", channel + 1, m_channel[1 - (offset / 8)].csrr, mem_mask);
13671332            if(channel == 0)
13681333            {
1369               return mcd212->channel[0].csrr;
1334               return m_channel[0].csrr;
13701335            }
13711336            else
13721337            {
1373               UINT8 old_csr = mcd212->channel[1].csrr;
1338               UINT8 old_csr = m_channel[1].csrr;
13741339               UINT8 interrupt1 = (state->m_scc->get_lir() >> 4) & 7;
13751340               //UINT8 interrupt2 = state->m_scc68070_regs.lir & 7;
1376               mcd212->channel[1].csrr &= ~(MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2);
1341               m_channel[1].csrr &= ~(MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2);
13771342               if(interrupt1)
13781343               {
13791344                  state->m_maincpu->set_input_line(M68K_IRQ_1 + (interrupt1 - 1), CLEAR_LINE);
r20519r20520
13871352         }
13881353         else
13891354         {
1390            verboselog(space.machine(), 2, "mcd212_r: Unknown Register %d: %04x\n", channel + 1, mem_mask);
1355            verboselog(machine(), 2, "mcd212_r: Unknown Register %d: %04x\n", channel + 1, mem_mask);
13911356         }
13921357         break;
13931358      case 0x02/2:
13941359      case 0x12/2:
1395         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);
1396         return mcd212->channel[1 - (offset / 8)].dcr;
1360         verboselog(machine(), 2, "mcd212_r: Display Command Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, m_channel[1 - (offset / 8)].dcr, mem_mask);
1361         return m_channel[1 - (offset / 8)].dcr;
13971362      case 0x04/2:
13981363      case 0x14/2:
1399         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);
1400         return mcd212->channel[1 - (offset / 8)].vsr;
1364         verboselog(machine(), 2, "mcd212_r: Video Start Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, m_channel[1 - (offset / 8)].vsr, mem_mask);
1365         return m_channel[1 - (offset / 8)].vsr;
14011366      case 0x08/2:
14021367      case 0x18/2:
1403         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);
1404         return mcd212->channel[1 - (offset / 8)].ddr;
1368         verboselog(machine(), 2, "mcd212_r: Display Decoder Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, m_channel[1 - (offset / 8)].ddr, mem_mask);
1369         return m_channel[1 - (offset / 8)].ddr;
14051370      case 0x0a/2:
14061371      case 0x1a/2:
1407         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);
1408         return mcd212->channel[1 - (offset / 8)].dcp;
1372         verboselog(machine(), 2, "mcd212_r: DCA Pointer Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, m_channel[1 - (offset / 8)].dcp, mem_mask);
1373         return m_channel[1 - (offset / 8)].dcp;
14091374      default:
1410         verboselog(space.machine(), 2, "mcd212_r: Unknown Register %d & %04x\n", (1 - (offset / 8)) + 1, mem_mask);
1375         verboselog(machine(), 2, "mcd212_r: Unknown Register %d & %04x\n", (1 - (offset / 8)) + 1, mem_mask);
14111376         break;
14121377   }
14131378
14141379   return 0;
14151380}
14161381
1417WRITE16_HANDLER( mcd212_w )
1382WRITE16_MEMBER( mcd212_device::regs_w )
14181383{
1419   cdi_state *state = space.machine().driver_data<cdi_state>();
1420   mcd212_regs_t *mcd212 = &state->m_mcd212_regs;
1421
14221384   switch(offset)
14231385   {
14241386      case 0x00/2:
14251387      case 0x10/2:
1426         verboselog(space.machine(), 2, "mcd212_w: Status Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1427         COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].csrw);
1428         mcd212_update_visible_area(space.machine());
1388         verboselog(machine(), 2, "mcd212_w: Status Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1389         COMBINE_DATA(&m_channel[1 - (offset / 8)].csrw);
1390         update_visible_area();
14291391         break;
14301392      case 0x02/2:
14311393      case 0x12/2:
1432         verboselog(space.machine(), 2, "mcd212_w: Display Command Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1433         COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].dcr);
1434         mcd212_update_visible_area(space.machine());
1394         verboselog(machine(), 2, "mcd212_w: Display Command Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1395         COMBINE_DATA(&m_channel[1 - (offset / 8)].dcr);
1396         update_visible_area();
14351397         break;
14361398      case 0x04/2:
14371399      case 0x14/2:
1438         verboselog(space.machine(), 2, "mcd212_w: Video Start Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1439         COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].vsr);
1400         verboselog(machine(), 2, "mcd212_w: Video Start Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1401         COMBINE_DATA(&m_channel[1 - (offset / 8)].vsr);
14401402         break;
14411403      case 0x08/2:
14421404      case 0x18/2:
1443         verboselog(space.machine(), 2, "mcd212_w: Display Decoder Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1444         COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].ddr);
1405         verboselog(machine(), 2, "mcd212_w: Display Decoder Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1406         COMBINE_DATA(&m_channel[1 - (offset / 8)].ddr);
14451407         break;
14461408      case 0x0a/2:
14471409      case 0x1a/2:
1448         verboselog(space.machine(), 2, "mcd212_w: DCA Pointer Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1449         COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].dcp);
1410         verboselog(machine(), 2, "mcd212_w: DCA Pointer Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1411         COMBINE_DATA(&m_channel[1 - (offset / 8)].dcp);
14501412         break;
14511413      default:
1452         verboselog(space.machine(), 2, "mcd212_w: Unknown Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1414         verboselog(machine(), 2, "mcd212_w: Unknown Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
14531415         break;
14541416   }
14551417}
14561418
1457TIMER_CALLBACK( mcd212_perform_scan )
1419TIMER_CALLBACK_MEMBER( mcd212_device::perform_scan )
14581420{
1459   cdi_state *state = machine.driver_data<cdi_state>();
1460   mcd212_regs_t *mcd212 = &state->m_mcd212_regs;
1461   int scanline = machine.primary_screen->vpos();
1421   int scanline = machine().primary_screen->vpos();
14621422
1463   if(/*mcd212->channel[0].dcr & MCD212_DCR_DE*/1)
1423   if(1)
14641424   {
14651425      if(scanline == 0)
14661426      {
14671427         // Process ICA
1468         int index = 0;
14691428         verboselog(machine, 6, "Frame Start\n" );
1470         mcd212->channel[0].csrr &= 0x7f;
1471         for(index = 0; index < 2; index++)
1429         m_channel[0].csrr &= 0x7f;
1430         for(int index = 0; index < 2; index++)
14721431         {
1473            if(mcd212->channel[index].dcr & MCD212_DCR_ICA)
1432            if(m_channel[index].dcr & MCD212_DCR_ICA)
14741433            {
1475               mcd212_process_ica(mcd212, index);
1434               process_ica(index);
14761435            }
14771436         }
1478         cdi220_draw_lcd(machine, scanline);
1437         draw_lcd(scanline);
14791438      }
14801439      else if(scanline < 22)
14811440      {
1482         cdi220_draw_lcd(machine, scanline);
1441         draw_lcd(scanline);
14831442      }
14841443      else if(scanline >= 22)
14851444      {
1486         int index = 0;
1487         mcd212->channel[0].csrr |= 0x80;
1445         m_channel[0].csrr |= 0x80;
14881446         // Process VSR
1489         mcd212_draw_scanline(mcd212, scanline);
1447         draw_scanline(scanline);
14901448         // Process DCA
1491         for(index = 0; index < 2; index++)
1449         for(int index = 0; index < 2; index++)
14921450         {
1493            if(mcd212->channel[index].dcr & MCD212_DCR_DCA)
1451            if(m_channel[index].dcr & MCD212_DCR_DCA)
14941452            {
14951453               if(scanline == 22)
14961454               {
1497                  mcd212->channel[index].dca = mcd212_get_dcp(mcd212, index);
1455                  m_channel[index].dca = get_dcp(index);
14981456               }
1499               mcd212_process_dca(mcd212, index);
1457               process_dca(index);
15001458            }
15011459         }
15021460         if(scanline == 301)
15031461         {
1504            mcd212->channel[0].csrr ^= 0x20;
1462            m_channel[0].csrr ^= 0x20;
15051463         }
15061464      }
15071465   }
1508   mcd212->scan_timer->adjust(machine.primary_screen->time_until_pos(( scanline + 1 ) % 302, 0));
1466   m_scan_timer->adjust(machine().primary_screen->time_until_pos(( scanline + 1 ) % 302, 0));
15091467}
15101468
1511void mcd212_init(running_machine &machine, mcd212_regs_t *mcd212)
1469void mcd212_device::device_reset()
15121470{
1513   mcd212->m_machine = &machine;
1514   machine.primary_screen->register_screen_bitmap(mcd212->m_bitmap);
1515
1516   int index = 0;
1517   for(index = 0; index < 2; index++)
1471   for(int index = 0; index < 2; index++)
15181472   {
1519      mcd212->channel[index].csrr = 0;
1520      mcd212->channel[index].csrw = 0;
1521      mcd212->channel[index].dcr = 0;
1522      mcd212->channel[index].vsr = 0;
1523      mcd212->channel[index].ddr = 0;
1524      mcd212->channel[index].dcp = 0;
1525      mcd212->channel[index].dca = 0;
1526      memset(mcd212->channel[index].clut_r, 0, 256);
1527      memset(mcd212->channel[index].clut_g, 0, 256);
1528      memset(mcd212->channel[index].clut_b, 0, 256);
1529      mcd212->channel[index].image_coding_method = 0;
1530      mcd212->channel[index].transparency_control = 0;
1531      mcd212->channel[index].plane_order = 0;
1532      mcd212->channel[index].clut_bank = 0;
1533      mcd212->channel[index].transparent_color_a = 0;
1534      mcd212->channel[index].transparent_color_b = 0;
1535      mcd212->channel[index].mask_color_a = 0;
1536      mcd212->channel[index].mask_color_b = 0;
1537      mcd212->channel[index].dyuv_abs_start_a = 0;
1538      mcd212->channel[index].dyuv_abs_start_b = 0;
1539      mcd212->channel[index].cursor_position = 0;
1540      mcd212->channel[index].cursor_control = 0;
1541      memset((UINT8*)&mcd212->channel[index].cursor_pattern, 0, 16 * sizeof(UINT32));
1542      memset((UINT8*)&mcd212->channel[index].region_control, 0, 8 * sizeof(UINT32));
1543      mcd212->channel[index].backdrop_color = 0;
1544      mcd212->channel[index].mosaic_hold_a = 0;
1545      mcd212->channel[index].mosaic_hold_b = 0;
1546      memset(mcd212->channel[index].weight_factor_a, 0, 768);
1547      memset(mcd212->channel[index].weight_factor_b, 0, 768);
1473      m_channel[index].csrr = 0;
1474      m_channel[index].csrw = 0;
1475      m_channel[index].dcr = 0;
1476      m_channel[index].vsr = 0;
1477      m_channel[index].ddr = 0;
1478      m_channel[index].dcp = 0;
1479      m_channel[index].dca = 0;
1480      memset(m_channel[index].clut_r, 0, 256);
1481      memset(m_channel[index].clut_g, 0, 256);
1482      memset(m_channel[index].clut_b, 0, 256);
1483      m_channel[index].image_coding_method = 0;
1484      m_channel[index].transparency_control = 0;
1485      m_channel[index].plane_order = 0;
1486      m_channel[index].clut_bank = 0;
1487      m_channel[index].transparent_color_a = 0;
1488      m_channel[index].transparent_color_b = 0;
1489      m_channel[index].mask_color_a = 0;
1490      m_channel[index].mask_color_b = 0;
1491      m_channel[index].dyuv_abs_start_a = 0;
1492      m_channel[index].dyuv_abs_start_b = 0;
1493      m_channel[index].cursor_position = 0;
1494      m_channel[index].cursor_control = 0;
1495      memset((UINT8*)&m_channel[index].cursor_pattern, 0, 16 * sizeof(UINT32));
1496      memset((UINT8*)&m_channel[index].region_control, 0, 8 * sizeof(UINT32));
1497      m_channel[index].backdrop_color = 0;
1498      m_channel[index].mosaic_hold_a = 0;
1499      m_channel[index].mosaic_hold_b = 0;
1500      memset(m_channel[index].weight_factor_a, 0, 768);
1501      memset(m_channel[index].weight_factor_b, 0, 768);
15481502   }
1549   memset(mcd212->region_flag_0, 0, 768);
1550   memset(mcd212->region_flag_1, 0, 768);
1503   memset(m_region_flag_0, 0, 768);
1504   memset(m_region_flag_1, 0, 768);
1505}
15511506
1552   state_save_register_global_array(machine, mcd212->region_flag_0);
1553   state_save_register_global_array(machine, mcd212->region_flag_1);
1554   state_save_register_global(machine, mcd212->channel[0].csrr);
1555   state_save_register_global(machine, mcd212->channel[0].csrw);
1556   state_save_register_global(machine, mcd212->channel[0].dcr);
1557   state_save_register_global(machine, mcd212->channel[0].vsr);
1558   state_save_register_global(machine, mcd212->channel[0].ddr);
1559   state_save_register_global(machine, mcd212->channel[0].dcp);
1560   state_save_register_global(machine, mcd212->channel[0].dca);
1561   state_save_register_global_array(machine, mcd212->channel[0].clut_r);
1562   state_save_register_global_array(machine, mcd212->channel[0].clut_g);
1563   state_save_register_global_array(machine, mcd212->channel[0].clut_b);
1564   state_save_register_global(machine, mcd212->channel[0].image_coding_method);
1565   state_save_register_global(machine, mcd212->channel[0].transparency_control);
1566   state_save_register_global(machine, mcd212->channel[0].plane_order);
1567   state_save_register_global(machine, mcd212->channel[0].clut_bank);
1568   state_save_register_global(machine, mcd212->channel[0].transparent_color_a);
1569   state_save_register_global(machine, mcd212->channel[0].transparent_color_b);
1570   state_save_register_global(machine, mcd212->channel[0].mask_color_a);
1571   state_save_register_global(machine, mcd212->channel[0].mask_color_b);
1572   state_save_register_global(machine, mcd212->channel[0].dyuv_abs_start_a);
1573   state_save_register_global(machine, mcd212->channel[0].dyuv_abs_start_b);
1574   state_save_register_global(machine, mcd212->channel[0].cursor_position);
1575   state_save_register_global(machine, mcd212->channel[0].cursor_control);
1576   state_save_register_global_array(machine, mcd212->channel[0].cursor_pattern);
1577   state_save_register_global_array(machine, mcd212->channel[0].region_control);
1578   state_save_register_global(machine, mcd212->channel[0].backdrop_color);
1579   state_save_register_global(machine, mcd212->channel[0].mosaic_hold_a);
1580   state_save_register_global(machine, mcd212->channel[0].mosaic_hold_b);
1581   state_save_register_global_array(machine, mcd212->channel[0].weight_factor_a);
1582   state_save_register_global_array(machine, mcd212->channel[0].weight_factor_b);
1583   state_save_register_global(machine, mcd212->channel[1].csrr);
1584   state_save_register_global(machine, mcd212->channel[1].csrw);
1585   state_save_register_global(machine, mcd212->channel[1].dcr);
1586   state_save_register_global(machine, mcd212->channel[1].vsr);
1587   state_save_register_global(machine, mcd212->channel[1].ddr);
1588   state_save_register_global(machine, mcd212->channel[1].dcp);
1589   state_save_register_global(machine, mcd212->channel[1].dca);
1590   state_save_register_global_array(machine, mcd212->channel[1].clut_r);
1591   state_save_register_global_array(machine, mcd212->channel[1].clut_g);
1592   state_save_register_global_array(machine, mcd212->channel[1].clut_b);
1593   state_save_register_global(machine, mcd212->channel[1].image_coding_method);
1594   state_save_register_global(machine, mcd212->channel[1].transparency_control);
1595   state_save_register_global(machine, mcd212->channel[1].plane_order);
1596   state_save_register_global(machine, mcd212->channel[1].clut_bank);
1597   state_save_register_global(machine, mcd212->channel[1].transparent_color_a);
1598   state_save_register_global(machine, mcd212->channel[1].transparent_color_b);
1599   state_save_register_global(machine, mcd212->channel[1].mask_color_a);
1600   state_save_register_global(machine, mcd212->channel[1].mask_color_b);
1601   state_save_register_global(machine, mcd212->channel[1].dyuv_abs_start_a);
1602   state_save_register_global(machine, mcd212->channel[1].dyuv_abs_start_b);
1603   state_save_register_global(machine, mcd212->channel[1].cursor_position);
1604   state_save_register_global(machine, mcd212->channel[1].cursor_control);
1605   state_save_register_global_array(machine, mcd212->channel[1].cursor_pattern);
1606   state_save_register_global_array(machine, mcd212->channel[1].region_control);
1607   state_save_register_global(machine, mcd212->channel[1].backdrop_color);
1608   state_save_register_global(machine, mcd212->channel[1].mosaic_hold_a);
1609   state_save_register_global(machine, mcd212->channel[1].mosaic_hold_b);
1610   state_save_register_global_array(machine, mcd212->channel[1].weight_factor_a);
1611   state_save_register_global_array(machine, mcd212->channel[1].weight_factor_b);
1507//-------------------------------------------------
1508//  mcd212_device - constructor
1509//-------------------------------------------------
1510
1511mcd212_device::mcd212_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
1512   : device_t(mconfig, MACHINE_MCD212, "MCD212", tag, owner, clock)
1513{
16121514}
16131515
1614void mcd212_ab_init(mcd212_ab_t *mcd212_ab)
1516//-------------------------------------------------
1517//  device_start - device-specific startup
1518//-------------------------------------------------
1519
1520void mcd212_device::device_start()
16151521{
1616   WORD68K w = 0;
1617   SWORD68K sw = 0;
1618   WORD68K d = 0;
1522   machine().primary_screen->register_screen_bitmap(m_bitmap);
16191523
1620   //* Delta decoding array.
1621   static const BYTE68K mcd212_abDelta[16] = { 0, 1, 4, 9, 16, 27, 44, 79, 128, 177, 212, 229, 240, 247, 252, 255 };
1524   m_scan_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mcd212_device::perform_scan), this));
1525   m_scan_timer->adjust(machine().primary_screen->time_until_pos(0, 0));
16221526
1527   save_item(NAME(m_region_flag_0));
1528   save_item(NAME(m_region_flag_1));
1529   save_item(NAME(m_channel[0].csrr));
1530   save_item(NAME(m_channel[0].csrw));
1531   save_item(NAME(m_channel[0].dcr));
1532   save_item(NAME(m_channel[0].vsr));
1533   save_item(NAME(m_channel[0].ddr));
1534   save_item(NAME(m_channel[0].dcp));
1535   save_item(NAME(m_channel[0].dca));
1536   save_item(NAME(m_channel[0].clut_r));
1537   save_item(NAME(m_channel[0].clut_g));
1538   save_item(NAME(m_channel[0].clut_b));
1539   save_item(NAME(m_channel[0].image_coding_method));
1540   save_item(NAME(m_channel[0].transparency_control));
1541   save_item(NAME(m_channel[0].plane_order));
1542   save_item(NAME(m_channel[0].clut_bank));
1543   save_item(NAME(m_channel[0].transparent_color_a));
1544   save_item(NAME(m_channel[0].transparent_color_b));
1545   save_item(NAME(m_channel[0].mask_color_a));
1546   save_item(NAME(m_channel[0].mask_color_b));
1547   save_item(NAME(m_channel[0].dyuv_abs_start_a));
1548   save_item(NAME(m_channel[0].dyuv_abs_start_b));
1549   save_item(NAME(m_channel[0].cursor_position));
1550   save_item(NAME(m_channel[0].cursor_control));
1551   save_item(NAME(m_channel[0].cursor_pattern));
1552   save_item(NAME(m_channel[0].region_control));
1553   save_item(NAME(m_channel[0].backdrop_color));
1554   save_item(NAME(m_channel[0].mosaic_hold_a));
1555   save_item(NAME(m_channel[0].mosaic_hold_b));
1556   save_item(NAME(m_channel[0].weight_factor_a));
1557   save_item(NAME(m_channel[0].weight_factor_b));
1558   save_item(NAME(m_channel[1].csrr));
1559   save_item(NAME(m_channel[1].csrw));
1560   save_item(NAME(m_channel[1].dcr));
1561   save_item(NAME(m_channel[1].vsr));
1562   save_item(NAME(m_channel[1].ddr));
1563   save_item(NAME(m_channel[1].dcp));
1564   save_item(NAME(m_channel[1].dca));
1565   save_item(NAME(m_channel[1].clut_r));
1566   save_item(NAME(m_channel[1].clut_g));
1567   save_item(NAME(m_channel[1].clut_b));
1568   save_item(NAME(m_channel[1].image_coding_method));
1569   save_item(NAME(m_channel[1].transparency_control));
1570   save_item(NAME(m_channel[1].plane_order));
1571   save_item(NAME(m_channel[1].clut_bank));
1572   save_item(NAME(m_channel[1].transparent_color_a));
1573   save_item(NAME(m_channel[1].transparent_color_b));
1574   save_item(NAME(m_channel[1].mask_color_a));
1575   save_item(NAME(m_channel[1].mask_color_b));
1576   save_item(NAME(m_channel[1].dyuv_abs_start_a));
1577   save_item(NAME(m_channel[1].dyuv_abs_start_b));
1578   save_item(NAME(m_channel[1].cursor_position));
1579   save_item(NAME(m_channel[1].cursor_control));
1580   save_item(NAME(m_channel[1].cursor_pattern));
1581   save_item(NAME(m_channel[1].region_control));
1582   save_item(NAME(m_channel[1].backdrop_color));
1583   save_item(NAME(m_channel[1].mosaic_hold_a));
1584   save_item(NAME(m_channel[1].mosaic_hold_b));
1585   save_item(NAME(m_channel[1].weight_factor_a));
1586   save_item(NAME(m_channel[1].weight_factor_b));
1587}
1588
1589void mcd212_device::ab_init()
1590{
1591   // Delta decoding array.
1592   static const BYTE68K abDelta[16] = { 0, 1, 4, 9, 16, 27, 44, 79, 128, 177, 212, 229, 240, 247, 252, 255 };
1593
16231594   // Initialize delta decoding arrays for each unsigned byte value b.
1624   for (d = 0; d < BYTE68K_MAX + 1; d++)
1595   for (WORD68K d = 0; d < BYTE68K_MAX + 1; d++)
16251596   {
1626      mcd212_ab->deltaY[d] = mcd212_abDelta[d & 15];
1597      m_ab.deltaY[d] = abDelta[d & 15];
16271598   }
16281599
16291600   // Initialize delta decoding arrays for each unsigned byte value b.
1630   for (d = 0; d < (BYTE68K_MAX + 1); d++)
1601   for (WORD68K d = 0; d < (BYTE68K_MAX + 1); d++)
16311602   {
1632      mcd212_ab->deltaUV[d] = mcd212_abDelta[d >> 4];
1603      m_ab.deltaUV[d] = abDelta[d >> 4];
16331604   }
16341605
16351606   // Initialize color limit and clamp arrays.
1636   for (w = 0; w < 3 * BYTE68K_MAX; w++)
1607   for (WORD68K w = 0; w < 3 * BYTE68K_MAX; w++)
16371608   {
1638      mcd212_ab->limit[w] = (w < BYTE68K_MAX + 16) ?  0 : w <= 16 + 2 * BYTE68K_MAX ? w - BYTE68K_MAX - 16 : BYTE68K_MAX;
1639      mcd212_ab->clamp[w] = (w < BYTE68K_MAX + 32) ? 16 : w <= 16 + 2 * BYTE68K_MAX ? w - BYTE68K_MAX - 16 : BYTE68K_MAX;
1609      m_ab.limit[w] = (w < BYTE68K_MAX + 16) ?  0 : w <= 16 + 2 * BYTE68K_MAX ? w - BYTE68K_MAX - 16 : BYTE68K_MAX;
1610      m_ab.clamp[w] = (w < BYTE68K_MAX + 32) ? 16 : w <= 16 + 2 * BYTE68K_MAX ? w - BYTE68K_MAX - 16 : BYTE68K_MAX;
16401611   }
16411612
1642   for (sw = 0; sw < 0x100; sw++)
1613   for (SWORD68K sw = 0; sw < 0x100; sw++)
16431614   {
1644      mcd212_ab->matrixUB[sw] = (444 * (sw - 128)) / 256;
1645      mcd212_ab->matrixUG[sw] = - (86 * (sw - 128)) / 256;
1646      mcd212_ab->matrixVG[sw] = - (179 * (sw - 128)) / 256;
1647      mcd212_ab->matrixVR[sw] = (351 * (sw - 128)) / 256;
1615      m_ab.matrixUB[sw] = (444 * (sw - 128)) / 256;
1616      m_ab.matrixUG[sw] = - (86 * (sw - 128)) / 256;
1617      m_ab.matrixVG[sw] = - (179 * (sw - 128)) / 256;
1618      m_ab.matrixVR[sw] = (351 * (sw - 128)) / 256;
16481619   }
16491620}
16501621
16511622void cdi_state::video_start()
16521623{
1653   mcd212_ab_init(&m_mcd212_ab);
1654   mcd212_init(machine(), &m_mcd212_regs);
1655   m_mcd212_regs.scan_timer = machine().scheduler().timer_alloc(FUNC(mcd212_perform_scan));
1656   m_mcd212_regs.scan_timer->adjust(machine().primary_screen->time_until_pos(0, 0));
1624   m_mcd212->ab_init();
16571625
16581626   screen_device *screen = downcast<screen_device *>(machine().device("lcd"));
16591627   screen->register_screen_bitmap(m_lcdbitmap);
r20519r20520
16611629
16621630UINT32 cdi_state::screen_update_cdimono1(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
16631631{
1664   copybitmap(bitmap, m_mcd212_regs.m_bitmap, 0, 0, 0, 0, cliprect);
1632   copybitmap(bitmap, m_mcd212->get_bitmap(), 0, 0, 0, 0, cliprect);
16651633   return 0;
16661634}
16671635
trunk/src/mame/video/mcd212.h
r20519r20520
2424
2525#include "emu.h"
2626
27struct mcd212_channel_t
28{
29   UINT8 csrr;
30   UINT16 csrw;
31   UINT16 dcr;
32   UINT16 vsr;
33   UINT16 ddr;
34   UINT16 dcp;
35   UINT32 dca;
36   UINT8 clut_r[256];
37   UINT8 clut_g[256];
38   UINT8 clut_b[256];
39   UINT32 image_coding_method;
40   UINT32 transparency_control;
41   UINT32 plane_order;
42   UINT32 clut_bank;
43   UINT32 transparent_color_a;
44   UINT32 reserved0;
45   UINT32 transparent_color_b;
46   UINT32 mask_color_a;
47   UINT32 reserved1;
48   UINT32 mask_color_b;
49   UINT32 dyuv_abs_start_a;
50   UINT32 dyuv_abs_start_b;
51   UINT32 reserved2;
52   UINT32 cursor_position;
53   UINT32 cursor_control;
54   UINT32 cursor_pattern[16];
55   UINT32 region_control[8];
56   UINT32 backdrop_color;
57   UINT32 mosaic_hold_a;
58   UINT32 mosaic_hold_b;
59   UINT8 weight_factor_a[768];
60   UINT8 weight_factor_b[768];
61};
62
63struct mcd212_regs_t
64{
65   running_machine &machine() const { assert(m_machine != NULL); return *m_machine; }
66
67   mcd212_channel_t channel[2];
68   emu_timer *scan_timer;
69   UINT8 region_flag_0[768];
70   UINT8 region_flag_1[768];
71
72   running_machine *m_machine;
73   bitmap_rgb32 m_bitmap;
74};
75
7627#define MCD212_CURCNT_COLOR         0x00000f    // Cursor color
7728#define MCD212_CURCNT_CUW           0x008000    // Cursor width
7829#define MCD212_CURCNT_COF           0x070000    // Cursor off time
r20519r20520
155106
156107#define BYTE68K_MAX 255
157108
109//**************************************************************************
110//  INTERFACE CONFIGURATION MACROS
111//**************************************************************************
158112
113#define MCFG_MCD212_ADD(_tag) \
114   MCFG_DEVICE_ADD(_tag, MACHINE_MCD212, 0)
115#define MCFG_MCD212_REPLACE(_tag) \
116   MCFG_DEVICE_REPLACE(_tag, MACHINE_MCD212, 0)
159117
160struct mcd212_ab_t
118
119//**************************************************************************
120//  TYPE DEFINITIONS
121//**************************************************************************
122
123// ======================> mcd212_device
124
125class mcd212_device : public device_t
161126{
162   //* Color limit array.
163   BYTE68K limit[3 * BYTE68K_MAX];
127public:
128   // construction/destruction
129   mcd212_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
164130
165   //* Color clamp array.
166   BYTE68K clamp[3 * BYTE68K_MAX];
131   // device members
132   DECLARE_READ16_MEMBER( regs_r );
133   DECLARE_WRITE16_MEMBER( regs_w );
134   TIMER_CALLBACK_MEMBER( perform_scan );
167135
168   //* U-to-B matrix array.
169   SWORD68K matrixUB[BYTE68K_MAX + 1];
136   void ab_init();
170137
171   //* U-to-G matrix array.
172   SWORD68K matrixUG[BYTE68K_MAX + 1];
138   bitmap_rgb32& get_bitmap() { return m_bitmap; }
173139
174   //* V-to-G matrix array.
175   SWORD68K matrixVG[BYTE68K_MAX + 1];
140   struct channel_t
141   {
142      UINT8 csrr;
143      UINT16 csrw;
144      UINT16 dcr;
145      UINT16 vsr;
146      UINT16 ddr;
147      UINT16 dcp;
148      UINT32 dca;
149      UINT8 clut_r[256];
150      UINT8 clut_g[256];
151      UINT8 clut_b[256];
152      UINT32 image_coding_method;
153      UINT32 transparency_control;
154      UINT32 plane_order;
155      UINT32 clut_bank;
156      UINT32 transparent_color_a;
157      UINT32 reserved0;
158      UINT32 transparent_color_b;
159      UINT32 mask_color_a;
160      UINT32 reserved1;
161      UINT32 mask_color_b;
162      UINT32 dyuv_abs_start_a;
163      UINT32 dyuv_abs_start_b;
164      UINT32 reserved2;
165      UINT32 cursor_position;
166      UINT32 cursor_control;
167      UINT32 cursor_pattern[16];
168      UINT32 region_control[8];
169      UINT32 backdrop_color;
170      UINT32 mosaic_hold_a;
171      UINT32 mosaic_hold_b;
172      UINT8 weight_factor_a[768];
173      UINT8 weight_factor_b[768];
174   };
176175
177   //* V-to-R matrix array.
178   SWORD68K matrixVR[BYTE68K_MAX + 1];
176   struct ab_t
177   {
178      //* Color limit array.
179      BYTE68K limit[3 * BYTE68K_MAX];
179180
180   //* Delta-Y decoding array.
181   BYTE68K deltaY[BYTE68K_MAX + 1];
181      //* Color clamp array.
182      BYTE68K clamp[3 * BYTE68K_MAX];
182183
183   //* Delta-U/V decoding array.
184   BYTE68K deltaUV[BYTE68K_MAX + 1];
184      //* U-to-B matrix array.
185      SWORD68K matrixUB[BYTE68K_MAX + 1];
186
187      //* U-to-G matrix array.
188      SWORD68K matrixUG[BYTE68K_MAX + 1];
189
190      //* V-to-G matrix array.
191      SWORD68K matrixVG[BYTE68K_MAX + 1];
192
193      //* V-to-R matrix array.
194      SWORD68K matrixVR[BYTE68K_MAX + 1];
195
196      //* Delta-Y decoding array.
197      BYTE68K deltaY[BYTE68K_MAX + 1];
198
199      //* Delta-U/V decoding array.
200      BYTE68K deltaUV[BYTE68K_MAX + 1];
201   };
202
203protected:
204   // device-level overrides
205   virtual void device_start();
206   virtual void device_reset();
207
208private:
209   // internal state
210   channel_t m_channel[2];
211   emu_timer *m_scan_timer;
212   UINT8 m_region_flag_0[768];
213   UINT8 m_region_flag_1[768];
214
215   bitmap_rgb32 m_bitmap;
216
217   static const UINT32 s_4bpp_color[16];
218
219   ab_t m_ab;
220
221   void update_region_arrays();
222
223   void set_vsr(int channel, UINT32 value);
224   UINT32 get_vsr(int channel);
225
226   void set_dcp(int channel, UINT32 value);
227   UINT32 get_dcp(int channel);
228
229   void set_display_parameters(int channel, UINT8 value);
230   void update_visible_area();
231   UINT32 get_screen_width();
232
233   void process_ica(int channel);
234   void process_dca(int channel);
235   void process_vsr(int channel, UINT8 *pixels_r, UINT8 *pixels_g, UINT8 *pixels_b);
236
237   void set_register(int channel, UINT8 reg, UINT32 value);
238
239   void mix_lines(UINT8 *plane_a_r, UINT8 *plane_a_g, UINT8 *plane_a_b, UINT8 *plane_b_r, UINT8 *plane_b_g, UINT8 *plane_b_b, UINT32 *out);
240
241   void draw_cursor(UINT32 *scanline, int y);
242   void draw_scanline(int y);
243
244   void draw_lcd(int y);
185245};
186246
187// Member functions
188DECLARE_READ16_HANDLER( mcd212_r );
189DECLARE_WRITE16_HANDLER( mcd212_w );
190TIMER_CALLBACK( mcd212_perform_scan );
191VIDEO_START( cdimono1 );
192SCREEN_UPDATE_RGB32( cdimono1 );
193SCREEN_UPDATE_RGB32( cdimono1_lcd );
247// device type definition
248extern const device_type MACHINE_MCD212;
194249
195250#endif // _VIDEO_MCD212_H_
trunk/src/mame/includes/cdi.h
r20519r20520
2828      m_slave(*this, "slave"),
2929      m_scc(*this, "scc68070"),
3030      m_cdic(*this, "cdic"),
31      m_cdda(*this, "cdda"){ }
31      m_cdda(*this, "cdda"),
32      m_mcd212(*this, "mcd212"){ }
3233
3334   required_device<cpu_device> m_maincpu;
3435   required_shared_ptr<UINT16> m_planea;
r20519r20520
4243   required_device<cdi68070_device> m_scc;
4344   required_device<cdicdic_device> m_cdic;
4445   required_device<cdda_device> m_cdda;
46   required_device<mcd212_device> m_mcd212;
4547
4648   dmadac_sound_device *m_dmadac[2];
4749
r20519r20520
5052   UINT8 m_timer_set;
5153   emu_timer *m_test_timer;
5254   bitmap_rgb32 m_lcdbitmap;
53   mcd212_regs_t m_mcd212_regs;
54   mcd212_ab_t m_mcd212_ab;
5555   DECLARE_INPUT_CHANGED_MEMBER(mcu_input);
5656   virtual void machine_start();
5757   virtual void video_start();

Previous 199869 Revisions Next


© 1997-2024 The MAME Team