From 221ed19f136fb117fd418e8138bea3b5e02d05d2 Mon Sep 17 00:00:00 2001 From: Ryan Holtz Date: Sat, 26 Jan 2013 23:18:19 +0000 Subject: [PATCH] [CDI] Modernize MCD212 device. [MooglyGuy] --- src/mame/drivers/cdi.c | 3 +- src/mame/includes/cdi.h | 6 +- src/mame/machine/cdicdic.h | 3 - src/mame/video/mcd212.c | 820 ++++++++++++++++++------------------- src/mame/video/mcd212.h | 201 +++++---- 5 files changed, 527 insertions(+), 506 deletions(-) diff --git a/src/mame/drivers/cdi.c b/src/mame/drivers/cdi.c index 807f0bea6b2..eaf19cdc3e7 100644 --- a/src/mame/drivers/cdi.c +++ b/src/mame/drivers/cdi.c @@ -67,7 +67,7 @@ static ADDRESS_MAP_START( cdimono1_mem, AS_PROGRAM, 16, cdi_state ) //AM_RANGE(0x00318000, 0x0031ffff) AM_NOP AM_RANGE(0x00320000, 0x00323fff) AM_DEVREADWRITE8_LEGACY("mk48t08", timekeeper_r, timekeeper_w, 0xff00) /* nvram (only low bytes used) */ AM_RANGE(0x00400000, 0x0047ffff) AM_ROM AM_REGION("maincpu", 0) - AM_RANGE(0x004fffe0, 0x004fffff) AM_READWRITE_LEGACY(mcd212_r, mcd212_w) + AM_RANGE(0x004fffe0, 0x004fffff) AM_DEVREADWRITE("mcd212", mcd212_device, regs_r, regs_w) //AM_RANGE(0x00500000, 0x0057ffff) AM_RAM AM_RANGE(0x00500000, 0x00ffffff) AM_NOP //AM_RANGE(0x00e00000, 0x00efffff) AM_RAM // DVC @@ -325,6 +325,7 @@ static MACHINE_CONFIG_START( cdi, cdi_state ) MCFG_CPU_ADD("maincpu", SCC68070, CLOCK_A/2) MCFG_CPU_PROGRAM_MAP(cdimono1_mem) + MCFG_MCD212_ADD("mcd212") MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(60) MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) diff --git a/src/mame/includes/cdi.h b/src/mame/includes/cdi.h index 0f761c89848..05c82116d62 100644 --- a/src/mame/includes/cdi.h +++ b/src/mame/includes/cdi.h @@ -28,7 +28,8 @@ public: m_slave(*this, "slave"), m_scc(*this, "scc68070"), m_cdic(*this, "cdic"), - m_cdda(*this, "cdda"){ } + m_cdda(*this, "cdda"), + m_mcd212(*this, "mcd212"){ } required_device m_maincpu; required_shared_ptr m_planea; @@ -42,6 +43,7 @@ public: required_device m_scc; required_device m_cdic; required_device m_cdda; + required_device m_mcd212; dmadac_sound_device *m_dmadac[2]; @@ -50,8 +52,6 @@ public: UINT8 m_timer_set; emu_timer *m_test_timer; bitmap_rgb32 m_lcdbitmap; - mcd212_regs_t m_mcd212_regs; - mcd212_ab_t m_mcd212_ab; DECLARE_INPUT_CHANGED_MEMBER(mcu_input); virtual void machine_start(); virtual void video_start(); diff --git a/src/mame/machine/cdicdic.h b/src/mame/machine/cdicdic.h index 5e038a338e5..1d8b4d2418f 100644 --- a/src/mame/machine/cdicdic.h +++ b/src/mame/machine/cdicdic.h @@ -69,8 +69,6 @@ protected: // device-level overrides virtual void device_start(); virtual void device_reset(); - virtual void device_post_load() { } - virtual void device_clock_changed() { } // internal callbacks TIMER_CALLBACK_MEMBER( audio_sample_trigger ); @@ -119,7 +117,6 @@ private: void decode_audio_sector(const UINT8 *xa, INT32 triggered); }; - // device type definition extern const device_type MACHINE_CDICDIC; diff --git a/src/mame/video/mcd212.c b/src/mame/video/mcd212.c index 8c51c529558..49aaef0b0ed 100644 --- a/src/mame/video/mcd212.c +++ b/src/mame/video/mcd212.c @@ -24,6 +24,9 @@ TODO: #include "video/mcd212.h" #include "includes/cdi.h" +// device type definition +const device_type MACHINE_MCD212 = &device_creator; + #if ENABLE_VERBOSE_LOG INLINE void verboselog(running_machine &machine, int n_level, const char *s_fmt, ...) { @@ -41,23 +44,6 @@ INLINE void verboselog(running_machine &machine, int n_level, const char *s_fmt, #define verboselog(x,y,z,...) #endif -static void cdi220_draw_lcd(running_machine &machine, int y); -static void mcd212_update_region_arrays(mcd212_regs_t *mcd212); -static void mcd212_set_display_parameters(mcd212_regs_t *mcd212, int channel, UINT8 value); -static void mcd212_update_visible_area(running_machine &machine); -static void mcd212_set_vsr(mcd212_regs_t *mcd212, int channel, UINT32 value); -static void mcd212_set_dcp(mcd212_regs_t *mcd212, int channel, UINT32 value); -static UINT32 mcd212_get_vsr(mcd212_regs_t *mcd212, int channel); -static UINT32 mcd212_get_dcp(mcd212_regs_t *mcd212, int channel); -static UINT32 mcd212_get_screen_width(mcd212_regs_t *mcd212); -static void mcd212_set_register(running_machine &machine, int channel, UINT8 reg, UINT32 value); -static void mcd212_process_ica(mcd212_regs_t *mcd212, int channel); -static void mcd212_process_dca(mcd212_regs_t *mcd212, int channel); -static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels_r, UINT8 *pixels_g, UINT8 *pixels_b); -static 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); -static void mcd212_draw_cursor(mcd212_regs_t *mcd212, UINT32 *scanline, int y); -static void mcd212_draw_scanline(mcd212_regs_t *mcd212, int y); - static const UINT16 cdi220_lcd_char[20*22] = { 0x2000, 0x2000, 0x2000, 0x2000, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0200, 0x0200, 0x0200, 0x0200, @@ -84,9 +70,9 @@ static const UINT16 cdi220_lcd_char[20*22] = 0x1000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0400, 0x0400, 0x0400, 0x0400 }; -static void cdi220_draw_lcd(running_machine &machine, int y) +void mcd212_device::draw_lcd(int y) { - cdi_state *state = machine.driver_data(); + cdi_state *state = machine().driver_data(); bitmap_rgb32 &bitmap = state->m_lcdbitmap; UINT32 *scanline = &bitmap.pix32(y); int x = 0; @@ -94,9 +80,8 @@ static void cdi220_draw_lcd(running_machine &machine, int y) for(lcd = 0; lcd < 8; lcd++) { - cdislave_device *slave = downcast(machine.device("slave")); - UINT16 data = (slave->get_lcd_state()[lcd*2] << 8) | - slave->get_lcd_state()[lcd*2 + 1]; + UINT16 data = (state->m_slave->get_lcd_state()[lcd*2] << 8) | + state->m_slave->get_lcd_state()[lcd*2 + 1]; for(x = 0; x < 20; x++) { if(data & cdi220_lcd_char[y*20 + x]) @@ -111,33 +96,29 @@ static void cdi220_draw_lcd(running_machine &machine, int y) } } -static void mcd212_update_region_arrays(mcd212_regs_t *mcd212) +void mcd212_device::update_region_arrays() { - int x = 0; int latched_rf0 = 0; int latched_rf1 = 0; - int latched_wfa = mcd212->channel[0].weight_factor_a[0]; - int latched_wfb = mcd212->channel[1].weight_factor_b[0]; + int latched_wfa = m_channel[0].weight_factor_a[0]; + int latched_wfb = m_channel[1].weight_factor_b[0]; int reg = 0; - for(x = 0; x < 768; x++) + for(int x = 0; x < 768; x++) { - if(mcd212->channel[0].image_coding_method & MCD212_ICM_NR) + if(m_channel[0].image_coding_method & MCD212_ICM_NR) { - int reg_ = 0; - int flag = 0; - - for(flag = 0; flag < 2; flag++) + for(int flag = 0; flag < 2; flag++) { - for(reg_ = 0; reg_ < 4; reg_++) + for(int reg_ = 0; reg_ < 4; reg_++) { - if(mcd212->channel[0].region_control[reg_] == 0) + if(m_channel[0].region_control[reg_] == 0) { break; } - if(x == (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_X)) + if(x == (m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_X)) { - switch((mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_OP) >> MCD212_RC_OP_SHIFT) + switch((m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_OP) >> MCD212_RC_OP_SHIFT) { case 0: // End of region control for line break; @@ -146,12 +127,12 @@ static void mcd212_update_region_arrays(mcd212_regs_t *mcd212) case 3: // Not used break; case 4: // Change weight of plane A - latched_wfa = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; + latched_wfa = (m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; break; case 5: // Not used break; case 6: // Change weight of plane B - latched_wfb = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; + latched_wfb = (m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; break; case 7: // Not used break; @@ -179,7 +160,7 @@ static void mcd212_update_region_arrays(mcd212_regs_t *mcd212) case 11: // Not used break; case 12: // Reset region flag and change weight of plane A - latched_wfa = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; + latched_wfa = (m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; if(flag) { latched_rf1 = 0; @@ -190,7 +171,7 @@ static void mcd212_update_region_arrays(mcd212_regs_t *mcd212) } break; case 13: // Set region flag and change weight of plane A - latched_wfa = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; + latched_wfa = (m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; if(flag) { latched_rf1 = 1; @@ -201,7 +182,7 @@ static void mcd212_update_region_arrays(mcd212_regs_t *mcd212) } break; case 14: // Reset region flag and change weight of plane B - latched_wfb = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; + latched_wfb = (m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; if(flag) { latched_rf1 = 0; @@ -212,7 +193,7 @@ static void mcd212_update_region_arrays(mcd212_regs_t *mcd212) } break; case 15: // Set region flag and change weight of plane B - latched_wfb = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; + latched_wfb = (m_channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; if(flag) { latched_rf1 = 1; @@ -231,21 +212,21 @@ static void mcd212_update_region_arrays(mcd212_regs_t *mcd212) { if(reg < 8) { - int flag = (mcd212->channel[0].region_control[reg] & MCD212_RC_RF) >> MCD212_RC_RF_SHIFT; - if(!(mcd212->channel[0].region_control[reg] & MCD212_RC_OP)) + int flag = (m_channel[0].region_control[reg] & MCD212_RC_RF) >> MCD212_RC_RF_SHIFT; + if(!(m_channel[0].region_control[reg] & MCD212_RC_OP)) { for(; x < 768; x++) { - mcd212->channel[0].weight_factor_a[x] = latched_wfa; - mcd212->channel[1].weight_factor_b[x] = latched_wfb; - mcd212->region_flag_0[x] = latched_rf0; - mcd212->region_flag_1[x] = latched_rf1; + m_channel[0].weight_factor_a[x] = latched_wfa; + m_channel[1].weight_factor_b[x] = latched_wfb; + m_region_flag_0[x] = latched_rf0; + m_region_flag_1[x] = latched_rf1; } break; } - if(x == (mcd212->channel[0].region_control[reg] & MCD212_RC_X)) + if(x == (m_channel[0].region_control[reg] & MCD212_RC_X)) { - switch((mcd212->channel[0].region_control[reg] & MCD212_RC_OP) >> MCD212_RC_OP_SHIFT) + switch((m_channel[0].region_control[reg] & MCD212_RC_OP) >> MCD212_RC_OP_SHIFT) { case 0: // End of region control for line break; @@ -254,12 +235,12 @@ static void mcd212_update_region_arrays(mcd212_regs_t *mcd212) case 3: // Not used break; case 4: // Change weight of plane A - latched_wfa = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; + latched_wfa = (m_channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; break; case 5: // Not used break; case 6: // Change weight of plane B - latched_wfb = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; + latched_wfb = (m_channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; break; case 7: // Not used break; @@ -287,7 +268,7 @@ static void mcd212_update_region_arrays(mcd212_regs_t *mcd212) case 11: // Not used break; case 12: // Reset region flag and change weight of plane A - latched_wfa = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; + latched_wfa = (m_channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; if(flag) { latched_rf1 = 0; @@ -298,7 +279,7 @@ static void mcd212_update_region_arrays(mcd212_regs_t *mcd212) } break; case 13: // Set region flag and change weight of plane A - latched_wfa = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; + latched_wfa = (m_channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; if(flag) { latched_rf1 = 1; @@ -309,7 +290,7 @@ static void mcd212_update_region_arrays(mcd212_regs_t *mcd212) } break; case 14: // Reset region flag and change weight of plane B - latched_wfb = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; + latched_wfb = (m_channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; if(flag) { latched_rf1 = 0; @@ -320,7 +301,7 @@ static void mcd212_update_region_arrays(mcd212_regs_t *mcd212) } break; case 15: // Set region flag and change weight of plane B - latched_wfb = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; + latched_wfb = (m_channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; if(flag) { latched_rf1 = 1; @@ -335,25 +316,22 @@ static void mcd212_update_region_arrays(mcd212_regs_t *mcd212) } } } - mcd212->channel[0].weight_factor_a[x] = latched_wfa; - mcd212->channel[1].weight_factor_b[x] = latched_wfb; - mcd212->region_flag_0[x] = latched_rf0; - mcd212->region_flag_1[x] = latched_rf1; + m_channel[0].weight_factor_a[x] = latched_wfa; + m_channel[1].weight_factor_b[x] = latched_wfb; + m_region_flag_0[x] = latched_rf0; + m_region_flag_1[x] = latched_rf1; } } -static void mcd212_set_vsr(mcd212_regs_t *mcd212, int channel, UINT32 value) +void mcd212_device::set_vsr(int channel, UINT32 value) { - mcd212->channel[channel].vsr = value & 0x0000ffff; - mcd212->channel[channel].dcr &= 0xffc0; - mcd212->channel[channel].dcr |= (value >> 16) & 0x003f; + m_channel[channel].vsr = value & 0x0000ffff; + m_channel[channel].dcr &= 0xffc0; + m_channel[channel].dcr |= (value >> 16) & 0x003f; } -static void mcd212_set_register(running_machine &machine, int channel, UINT8 reg, UINT32 value) +void mcd212_device::set_register(int channel, UINT8 reg, UINT32 value) { - cdi_state *state = machine.driver_data(); - mcd212_regs_t *mcd212 = &state->m_mcd212_regs; - switch(reg) { case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: // CLUT 0 - 63 @@ -364,97 +342,97 @@ static void mcd212_set_register(running_machine &machine, int channel, UINT8 reg case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf: case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7: case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf: - verboselog(machine, 11, " %04xxxxx: %d: CLUT[%d] = %08x\n", channel * 0x20, channel, mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80), value ); - mcd212->channel[0].clut_r[mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >> 16) & 0xfc; - mcd212->channel[0].clut_g[mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >> 8) & 0xfc; - mcd212->channel[0].clut_b[mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >> 0) & 0xfc; + verboselog(machine, 11, " %04xxxxx: %d: CLUT[%d] = %08x\n", channel * 0x20, channel, m_channel[channel].clut_bank * 0x40 + (reg - 0x80), value ); + m_channel[0].clut_r[m_channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >> 16) & 0xfc; + m_channel[0].clut_g[m_channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >> 8) & 0xfc; + m_channel[0].clut_b[m_channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >> 0) & 0xfc; break; case 0xc0: // Image Coding Method if(channel == 0) { verboselog(machine, 6, " %04xxxxx: %d: Image Coding Method = %08x\n", channel * 0x20, channel, value ); - mcd212->channel[channel].image_coding_method = value; + m_channel[channel].image_coding_method = value; } break; case 0xc1: // Transparency Control if(channel == 0) { verboselog(machine, 6, " %04xxxxx: %d: Transparency Control = %08x\n", channel * 0x20, channel, value ); - mcd212->channel[channel].transparency_control = value; + m_channel[channel].transparency_control = value; } break; case 0xc2: // Plane Order if(channel == 0) { verboselog(machine, 6, " %04xxxxx: %d: Plane Order = %08x\n", channel * 0x20, channel, value & 7); - mcd212->channel[channel].plane_order = value & 0x00000007; + m_channel[channel].plane_order = value & 0x00000007; } break; case 0xc3: // CLUT Bank Register verboselog(machine, 6, " %04xxxxx: %d: CLUT Bank Register = %08x\n", channel * 0x20, channel, value & 3); - mcd212->channel[channel].clut_bank = channel ? (2 | (value & 0x00000001)) : (value & 0x00000003); + m_channel[channel].clut_bank = channel ? (2 | (value & 0x00000001)) : (value & 0x00000003); break; case 0xc4: // Transparent Color A if(channel == 0) { verboselog(machine, 6, " %04xxxxx: %d: Transparent Color A = %08x\n", channel * 0x20, channel, value ); - mcd212->channel[channel].transparent_color_a = value & 0xfcfcfc; + m_channel[channel].transparent_color_a = value & 0xfcfcfc; } break; case 0xc6: // Transparent Color B if(channel == 1) { verboselog(machine, 6, " %04xxxxx: %d: Transparent Color B = %08x\n", channel * 0x20, channel, value ); - mcd212->channel[channel].transparent_color_b = value & 0xfcfcfc; + m_channel[channel].transparent_color_b = value & 0xfcfcfc; } break; case 0xc7: // Mask Color A if(channel == 0) { verboselog(machine, 6, " %04xxxxx: %d: Mask Color A = %08x\n", channel * 0x20, channel, value ); - mcd212->channel[channel].mask_color_a = value & 0xfcfcfc; + m_channel[channel].mask_color_a = value & 0xfcfcfc; } break; case 0xc9: // Mask Color B if(channel == 1) { verboselog(machine, 6, " %04xxxxx: %d: Mask Color B = %08x\n", channel * 0x20, channel, value ); - mcd212->channel[channel].mask_color_b = value & 0xfcfcfc; + m_channel[channel].mask_color_b = value & 0xfcfcfc; } break; case 0xca: // Delta YUV Absolute Start Value A if(channel == 0) { verboselog(machine, 6, " %04xxxxx: %d: Delta YUV Absolute Start Value A = %08x\n", channel * 0x20, channel, value ); - mcd212->channel[channel].dyuv_abs_start_a = value; + m_channel[channel].dyuv_abs_start_a = value; } break; case 0xcb: // Delta YUV Absolute Start Value B if(channel == 1) { verboselog(machine, 6, " %04xxxxx: %d: Delta YUV Absolute Start Value B = %08x\n", channel * 0x20, channel, value ); - mcd212->channel[channel].dyuv_abs_start_b = value; + m_channel[channel].dyuv_abs_start_b = value; } break; case 0xcd: // Cursor Position if(channel == 0) { verboselog(machine, 6, " %04xxxxx: %d: Cursor Position = %08x\n", channel * 0x20, channel, value ); - mcd212->channel[channel].cursor_position = value; + m_channel[channel].cursor_position = value; } break; case 0xce: // Cursor Control if(channel == 0) { verboselog(machine, 11, " %04xxxxx: %d: Cursor Control = %08x\n", channel * 0x20, channel, value ); - mcd212->channel[channel].cursor_control = value; + m_channel[channel].cursor_control = value; } break; case 0xcf: // Cursor Pattern if(channel == 0) { verboselog(machine, 11, " %04xxxxx: %d: Cursor Pattern[%d] = %04x\n", channel * 0x20, channel, (value >> 16) & 0x000f, value & 0x0000ffff); - mcd212->channel[channel].cursor_pattern[(value >> 16) & 0x000f] = value & 0x0000ffff; + m_channel[channel].cursor_pattern[(value >> 16) & 0x000f] = value & 0x0000ffff; } break; case 0xd0: // Region Control 0-7 @@ -466,84 +444,82 @@ static void mcd212_set_register(running_machine &machine, int channel, UINT8 reg case 0xd6: case 0xd7: verboselog(machine, 6, " %04xxxxx: %d: Region Control %d = %08x\n", channel * 0x20, channel, reg & 7, value ); - mcd212->channel[0].region_control[reg & 7] = value; - mcd212_update_region_arrays(mcd212); + m_channel[0].region_control[reg & 7] = value; + update_region_arrays(); break; case 0xd8: // Backdrop Color if(channel == 0) { verboselog(machine, 6, " %04xxxxx: %d: Backdrop Color = %08x\n", channel * 0x20, channel, value ); - mcd212->channel[channel].backdrop_color = value; + m_channel[channel].backdrop_color = value; } break; case 0xd9: // Mosaic Pixel Hold Factor A if(channel == 0) { verboselog(machine, 6, " %04xxxxx: %d: Mosaic Pixel Hold Factor A = %08x\n", channel * 0x20, channel, value ); - mcd212->channel[channel].mosaic_hold_a = value; + m_channel[channel].mosaic_hold_a = value; } break; case 0xda: // Mosaic Pixel Hold Factor B if(channel == 1) { verboselog(machine, 6, " %04xxxxx: %d: Mosaic Pixel Hold Factor B = %08x\n", channel * 0x20, channel, value ); - mcd212->channel[channel].mosaic_hold_b = value; + m_channel[channel].mosaic_hold_b = value; } break; case 0xdb: // Weight Factor A if(channel == 0) { verboselog(machine, 6, " %04xxxxx: %d: Weight Factor A = %08x\n", channel * 0x20, channel, value ); - memset(mcd212->channel[channel].weight_factor_a, value & 0x000000ff, 768); - mcd212_update_region_arrays(mcd212); + memset(m_channel[channel].weight_factor_a, value & 0x000000ff, 768); + update_region_arrays(); } break; case 0xdc: // Weight Factor B if(channel == 1) { verboselog(machine, 6, " %04xxxxx: %d: Weight Factor B = %08x\n", channel * 0x20, channel, value ); - memset(mcd212->channel[channel].weight_factor_b, value & 0x000000ff, 768); - mcd212_update_region_arrays(mcd212); + memset(m_channel[channel].weight_factor_b, value & 0x000000ff, 768); + update_region_arrays(); } break; } } -static UINT32 mcd212_get_vsr(mcd212_regs_t *mcd212, int channel) +UINT32 mcd212_device::get_vsr(int channel) { - return ((mcd212->channel[channel].dcr & 0x3f) << 16) | mcd212->channel[channel].vsr; + return ((m_channel[channel].dcr & 0x3f) << 16) | m_channel[channel].vsr; } -static void mcd212_set_dcp(mcd212_regs_t *mcd212, int channel, UINT32 value) +void mcd212_device::set_dcp(int channel, UINT32 value) { - mcd212->channel[channel].dcp = value & 0x0000ffff; - mcd212->channel[channel].ddr &= 0xffc0; - mcd212->channel[channel].ddr |= (value >> 16) & 0x003f; + m_channel[channel].dcp = value & 0x0000ffff; + m_channel[channel].ddr &= 0xffc0; + m_channel[channel].ddr |= (value >> 16) & 0x003f; } -static UINT32 mcd212_get_dcp(mcd212_regs_t *mcd212, int channel) +UINT32 mcd212_device::get_dcp(int channel) { - return ((mcd212->channel[channel].ddr & 0x3f) << 16) | mcd212->channel[channel].dcp; + return ((m_channel[channel].ddr & 0x3f) << 16) | m_channel[channel].dcp; } -static void mcd212_set_display_parameters(mcd212_regs_t *mcd212, int channel, UINT8 value) +void mcd212_device::set_display_parameters(int channel, UINT8 value) { - mcd212->channel[channel].ddr &= 0xf0ff; - mcd212->channel[channel].ddr |= (value & 0x0f) << 8; - mcd212->channel[channel].dcr &= 0xf7ff; - mcd212->channel[channel].dcr |= (value & 0x10) << 7; + m_channel[channel].ddr &= 0xf0ff; + m_channel[channel].ddr |= (value & 0x0f) << 8; + m_channel[channel].dcr &= 0xf7ff; + m_channel[channel].dcr |= (value & 0x10) << 7; } -static void mcd212_update_visible_area(running_machine &machine) +void mcd212_device::update_visible_area() { - cdi_state *state = machine.driver_data(); - mcd212_regs_t *mcd212 = &state->m_mcd212_regs; - const rectangle &visarea = machine.primary_screen->visible_area(); + const rectangle &visarea = machine().primary_screen->visible_area(); rectangle visarea1; - attoseconds_t period = machine.primary_screen->frame_period().attoseconds; + attoseconds_t period = machine().primary_screen->frame_period().attoseconds; int width = 0; - if((mcd212->channel[0].dcr & (MCD212_DCR_CF | MCD212_DCR_FD)) && (mcd212->channel[0].csrw & MCD212_CSR1W_ST)) + if((m_channel[0].dcr & (MCD212_DCR_CF | MCD212_DCR_FD)) && (m_channel[0].csrw & MCD212_CSR1W_ST)) { width = 360; } @@ -557,22 +533,21 @@ static void mcd212_update_visible_area(running_machine &machine) visarea1.min_y = visarea.min_y; visarea1.max_y = visarea.max_y; - machine.primary_screen->configure(width, 302, visarea1, period); + machine().primary_screen->configure(width, 302, visarea1, period); } -static UINT32 mcd212_get_screen_width(mcd212_regs_t *mcd212) +UINT32 mcd212_device::get_screen_width() { - if((mcd212->channel[0].dcr & (MCD212_DCR_CF | MCD212_DCR_FD)) && (mcd212->channel[0].csrw & MCD212_CSR1W_ST)) + if((m_channel[0].dcr & (MCD212_DCR_CF | MCD212_DCR_FD)) && (m_channel[0].csrw & MCD212_CSR1W_ST)) { return 720; } return 768; } -static void mcd212_process_ica(mcd212_regs_t *mcd212, int channel) +void mcd212_device::process_ica(int channel) { - running_machine &machine = mcd212->machine(); - cdi_state *state = machine.driver_data(); + cdi_state *state = machine().driver_data(); UINT16 *ica = channel ? state->m_planeb : state->m_planea; UINT32 addr = 0x000400/2; UINT32 cmd = 0; @@ -595,12 +570,12 @@ static void mcd212_process_ica(mcd212_regs_t *mcd212, int channel) case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: // RELOAD DCP case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f: verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD DCP\n", addr * 2 + channel * 0x200000, cmd, channel ); - mcd212_set_dcp(mcd212, channel, cmd & 0x001fffff); + set_dcp(channel, cmd & 0x001fffff); break; case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: // RELOAD DCP and STOP case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f: verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD DCP and STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); - mcd212_set_dcp(mcd212, channel, cmd & 0x001fffff); + set_dcp(channel, cmd & 0x001fffff); stop = 1; break; case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: // RELOAD ICA @@ -611,14 +586,14 @@ static void mcd212_process_ica(mcd212_regs_t *mcd212, int channel) case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: // RELOAD VSR and STOP case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f: verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD VSR and STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); - mcd212_set_vsr(mcd212, channel, cmd & 0x001fffff); + set_vsr(channel, cmd & 0x001fffff); stop = 1; break; case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: // INTERRUPT case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: verboselog(machine, 11, "%08x: %08x: ICA %d: INTERRUPT\n", addr * 2 + channel * 0x200000, cmd, channel ); - mcd212->channel[1].csrr |= 1 << (2 - channel); - if(mcd212->channel[1].csrr & (MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2)) + m_channel[1].csrr |= 1 << (2 - channel); + if(m_channel[1].csrr & (MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2)) { UINT8 interrupt = (state->m_scc->get_lir() >> 4) & 7; if(interrupt) @@ -628,7 +603,7 @@ static void mcd212_process_ica(mcd212_regs_t *mcd212, int channel) } } #if 0 - if(mcd212->channel[1].csrr & MCD212_CSR2R_IT2) + if(m_channel[1].csrr & MCD212_CSR2R_IT2) { UINT8 interrupt = state->m_scc68070_regs.lir & 7; if(interrupt) @@ -641,10 +616,10 @@ static void mcd212_process_ica(mcd212_regs_t *mcd212, int channel) break; case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: // RELOAD DISPLAY PARAMETERS verboselog(machine, 6, "%08x: %08x: ICA %d: RELOAD DISPLAY PARAMETERS\n", addr * 2 + channel * 0x200000, cmd, channel ); - mcd212_set_display_parameters(mcd212, channel, cmd & 0x1f); + set_display_parameters(channel, cmd & 0x1f); break; default: - mcd212_set_register(machine, channel, cmd >> 24, cmd & 0x00ffffff); + set_register(channel, cmd >> 24, cmd & 0x00ffffff); break; } if(stop) @@ -654,12 +629,11 @@ static void mcd212_process_ica(mcd212_regs_t *mcd212, int channel) } } -static void mcd212_process_dca(mcd212_regs_t *mcd212, int channel) +void mcd212_device::process_dca(int channel) { - running_machine &machine = mcd212->machine(); - cdi_state *state = machine.driver_data(); + cdi_state *state = machine().driver_data(); UINT16 *dca = channel ? state->m_planeb : state->m_planea; - UINT32 addr = (mcd212->channel[channel].dca & 0x0007ffff) / 2; //(mcd212_get_dcp(mcd212, channel) & 0x0007ffff) / 2; // mcd212->channel[channel].dca / 2; + UINT32 addr = (m_channel[channel].dca & 0x0007ffff) / 2; //(get_dcp(mcd212, channel) & 0x0007ffff) / 2; // m_channel[channel].dca / 2; UINT32 cmd = 0; UINT32 count = 0; UINT32 max = 64; @@ -689,7 +663,7 @@ static void mcd212_process_dca(mcd212_regs_t *mcd212, int channel) case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: // RELOAD DCP and STOP case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f: verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD DCP and STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); - mcd212_set_dcp(&state->m_mcd212_regs, channel, cmd & 0x001fffff); + set_dcp(channel, cmd & 0x001fffff); addr = (cmd & 0x0007ffff) / 2; addr_changed = 1; stop = 1; @@ -697,19 +671,19 @@ static void mcd212_process_dca(mcd212_regs_t *mcd212, int channel) case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: // RELOAD VSR case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f: verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD VSR\n", addr * 2 + channel * 0x200000, cmd, channel ); - mcd212_set_vsr(&state->m_mcd212_regs, channel, cmd & 0x001fffff); + set_vsr(channel, cmd & 0x001fffff); break; case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: // RELOAD VSR and STOP case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f: verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD VSR and STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); - mcd212_set_vsr(&state->m_mcd212_regs, channel, cmd & 0x001fffff); + set_vsr(channel, cmd & 0x001fffff); stop = 1; break; case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: // INTERRUPT case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: verboselog(machine, 11, "%08x: %08x: DCA %d: INTERRUPT\n", addr * 2 + channel * 0x200000, cmd, channel ); - mcd212->channel[1].csrr |= 1 << (2 - channel); - if(mcd212->channel[1].csrr & (MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2)) + m_channel[1].csrr |= 1 << (2 - channel); + if(m_channel[1].csrr & (MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2)) { UINT8 interrupt = (state->m_scc->get_lir() >> 4) & 7; if(interrupt) @@ -719,7 +693,7 @@ static void mcd212_process_dca(mcd212_regs_t *mcd212, int channel) } } #if 0 - if(mcd212->channel[1].csrr & MCD212_CSR2R_IT2) + if(m_channel[1].csrr & MCD212_CSR2R_IT2) { UINT8 interrupt = state->m_scc68070_regs.lir & 7; if(interrupt) @@ -732,10 +706,10 @@ static void mcd212_process_dca(mcd212_regs_t *mcd212, int channel) break; case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: // RELOAD DISPLAY PARAMETERS verboselog(machine, 6, "%08x: %08x: DCA %d: RELOAD DISPLAY PARAMETERS\n", addr * 2 + channel * 0x200000, cmd, channel ); - mcd212_set_display_parameters(&state->m_mcd212_regs, channel, cmd & 0x1f); + set_display_parameters(channel, cmd & 0x1f); break; default: - mcd212_set_register(machine, channel, cmd >> 24, cmd & 0x00ffffff); + set_register(channel, cmd >> 24, cmd & 0x00ffffff); break; } if(stop != 0 || count == max) @@ -750,7 +724,7 @@ static void mcd212_process_dca(mcd212_regs_t *mcd212, int channel) addr += (max - count) >> 1; } } - mcd212->channel[channel].dca = addr * 2; + m_channel[channel].dca = addr * 2; } INLINE UINT8 MCD212_LIM(INT32 in) @@ -802,24 +776,23 @@ INLINE UINT8 BYTE_TO_CLUT(int channel, int icm, UINT8 byte) return 0; } -static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels_r, UINT8 *pixels_g, UINT8 *pixels_b) +void mcd212_device::process_vsr(int channel, UINT8 *pixels_r, UINT8 *pixels_g, UINT8 *pixels_b) { - running_machine &machine = mcd212->machine(); - cdi_state *state = machine.driver_data(); + cdi_state *state = machine().driver_data(); UINT8 *data = reinterpret_cast(channel ? state->m_planeb.target() : state->m_planea.target()); - UINT32 vsr = mcd212_get_vsr(mcd212, channel) & 0x0007ffff; + UINT32 vsr = get_vsr(channel) & 0x0007ffff; UINT8 done = 0; UINT32 x = 0; UINT32 icm_mask = channel ? MCD212_ICM_MODE2 : MCD212_ICM_MODE1; UINT32 icm_shift = channel ? MCD212_ICM_MODE2_SHIFT : MCD212_ICM_MODE1_SHIFT; - UINT8 icm = (mcd212->channel[0].image_coding_method & icm_mask) >> icm_shift; - UINT8 *clut_r = mcd212->channel[0].clut_r; - UINT8 *clut_g = mcd212->channel[0].clut_g; - UINT8 *clut_b = mcd212->channel[0].clut_b; - UINT8 mosaic_enable = ((mcd212->channel[channel].ddr & MCD212_DDR_FT) == MCD212_DDR_FT_MOSAIC); - UINT8 mosaic_factor = 1 << (((mcd212->channel[channel].ddr & MCD212_DDR_MT) >> MCD212_DDR_MT_SHIFT) + 1); + UINT8 icm = (m_channel[0].image_coding_method & icm_mask) >> icm_shift; + UINT8 *clut_r = m_channel[0].clut_r; + UINT8 *clut_g = m_channel[0].clut_g; + UINT8 *clut_b = m_channel[0].clut_b; + UINT8 mosaic_enable = ((m_channel[channel].ddr & MCD212_DDR_FT) == MCD212_DDR_FT_MOSAIC); + UINT8 mosaic_factor = 1 << (((m_channel[channel].ddr & MCD212_DDR_MT) >> MCD212_DDR_MT_SHIFT) + 1); int mosaic_index = 0; - UINT32 width = mcd212_get_screen_width(mcd212); + UINT32 width = get_screen_width(); //printf( "vsr before: %08x: ", vsr ); //fflush(stdout); @@ -836,12 +809,12 @@ static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels { UINT8 byte = data[(vsr & 0x0007ffff) ^ 1]; vsr++; - switch(mcd212->channel[channel].ddr & MCD212_DDR_FT) + switch(m_channel[channel].ddr & MCD212_DDR_FT) { case MCD212_DDR_FT_BMP: case MCD212_DDR_FT_BMP2: case MCD212_DDR_FT_MOSAIC: - if(mcd212->channel[channel].dcr & MCD212_DCR_CM) + if(m_channel[channel].dcr & MCD212_DCR_CM) { // 4-bit Bitmap verboselog(machine, 0, "Unsupported display mode: 4-bit Bitmap\n" ); @@ -857,14 +830,14 @@ static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels switch(channel) { case 0: - bY = (mcd212->channel[0].dyuv_abs_start_a >> 16) & 0x000000ff; - bU = (mcd212->channel[0].dyuv_abs_start_a >> 8) & 0x000000ff; - bV = (mcd212->channel[0].dyuv_abs_start_a >> 0) & 0x000000ff; + bY = (m_channel[0].dyuv_abs_start_a >> 16) & 0x000000ff; + bU = (m_channel[0].dyuv_abs_start_a >> 8) & 0x000000ff; + bV = (m_channel[0].dyuv_abs_start_a >> 0) & 0x000000ff; break; case 1: - bY = (mcd212->channel[1].dyuv_abs_start_b >> 16) & 0x000000ff; - bU = (mcd212->channel[1].dyuv_abs_start_b >> 8) & 0x000000ff; - bV = (mcd212->channel[1].dyuv_abs_start_b >> 0) & 0x000000ff; + bY = (m_channel[1].dyuv_abs_start_b >> 16) & 0x000000ff; + bU = (m_channel[1].dyuv_abs_start_b >> 8) & 0x000000ff; + bV = (m_channel[1].dyuv_abs_start_b >> 0) & 0x000000ff; break; default: bY = bU = bV = 0x80; @@ -873,12 +846,12 @@ static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels for(; x < width; x += 2) { BYTE68K b0 = byte; - BYTE68K bU1 = bU + state->m_mcd212_ab.deltaUV[b0]; - BYTE68K bY0 = bY + state->m_mcd212_ab.deltaY[b0]; + BYTE68K bU1 = bU + m_ab.deltaUV[b0]; + BYTE68K bY0 = bY + m_ab.deltaY[b0]; BYTE68K b1 = data[(vsr & 0x0007ffff) ^ 1]; - BYTE68K bV1 = bV + state->m_mcd212_ab.deltaUV[b1]; - BYTE68K bY1 = bY0 + state->m_mcd212_ab.deltaY[b1]; + BYTE68K bV1 = bV + m_ab.deltaUV[b1]; + BYTE68K bY1 = bY0 + m_ab.deltaY[b1]; BYTE68K bU0 = (bU + bU1) >> 1; BYTE68K bV0 = (bV + bV1) >> 1; @@ -891,11 +864,11 @@ static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels bU = bU0; bV = bV0; - pbLimit = state->m_mcd212_ab.limit + bY + BYTE68K_MAX; + pbLimit = m_ab.limit + bY + BYTE68K_MAX; - pixels_r[x + 0] = pixels_r[x + 1] = pbLimit[state->m_mcd212_ab.matrixVR[bV]]; - pixels_g[x + 0] = pixels_g[x + 1] = pbLimit[state->m_mcd212_ab.matrixUG[bU] + state->m_mcd212_ab.matrixVG[bV]]; - pixels_b[x + 0] = pixels_b[x + 1] = pbLimit[state->m_mcd212_ab.matrixUB[bU]]; + pixels_r[x + 0] = pixels_r[x + 1] = pbLimit[m_ab.matrixVR[bV]]; + pixels_g[x + 0] = pixels_g[x + 1] = pbLimit[m_ab.matrixUG[bU] + m_ab.matrixVG[bV]]; + pixels_b[x + 0] = pixels_b[x + 1] = pbLimit[m_ab.matrixUB[bU]]; if(mosaic_enable) { @@ -919,11 +892,11 @@ static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels bU = bU1; bV = bV1; - pbLimit = state->m_mcd212_ab.limit + bY + BYTE68K_MAX; + pbLimit = m_ab.limit + bY + BYTE68K_MAX; - pixels_r[x + 0] = pixels_r[x + 1] = pbLimit[state->m_mcd212_ab.matrixVR[bV]]; - pixels_g[x + 0] = pixels_g[x + 1] = pbLimit[state->m_mcd212_ab.matrixUG[bU] + state->m_mcd212_ab.matrixVG[bV]]; - pixels_b[x + 0] = pixels_b[x + 1] = pbLimit[state->m_mcd212_ab.matrixUB[bU]]; + pixels_r[x + 0] = pixels_r[x + 1] = pbLimit[m_ab.matrixVR[bV]]; + pixels_g[x + 0] = pixels_g[x + 1] = pbLimit[m_ab.matrixUG[bU] + m_ab.matrixVG[bV]]; + pixels_b[x + 0] = pixels_b[x + 1] = pbLimit[m_ab.matrixUB[bU]]; if(mosaic_enable) { @@ -943,7 +916,7 @@ static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels vsr++; } - mcd212_set_vsr(&state->m_mcd212_regs, channel, (vsr - 1) & 0x0007ffff); + set_vsr(channel, (vsr - 1) & 0x0007ffff); } else if(icm == 1 || icm == 3 || icm == 4) { @@ -972,7 +945,7 @@ static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels byte = data[(vsr & 0x0007ffff) ^ 1]; vsr++; } - mcd212_set_vsr(&state->m_mcd212_regs, channel, (vsr - 1) & 0x0007ffff); + set_vsr(channel, (vsr - 1) & 0x0007ffff); } else if(icm == 11) { @@ -1008,7 +981,7 @@ static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels byte = data[(vsr & 0x0007ffff) ^ 1]; vsr++; } - mcd212_set_vsr(&state->m_mcd212_regs, channel, (vsr - 1) & 0x0007ffff); + set_vsr(channel, (vsr - 1) & 0x0007ffff); } else { @@ -1023,7 +996,7 @@ static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels done = 1; break; case MCD212_DDR_FT_RLE: - if(mcd212->channel[channel].dcr & MCD212_DCR_CM) + if(m_channel[channel].dcr & MCD212_DCR_CM) { verboselog(machine, 0, "Unsupported display mode: 4-bit RLE\n" ); done = 1; @@ -1052,7 +1025,7 @@ static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels pixels_b[x] = b; } done = 1; - mcd212_set_vsr(&state->m_mcd212_regs, channel, vsr); + set_vsr(channel, vsr); } else { @@ -1074,7 +1047,7 @@ static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels if(x >= width) { done = 1; - mcd212_set_vsr(&state->m_mcd212_regs, channel, vsr); + set_vsr(channel, vsr); } } } @@ -1093,7 +1066,7 @@ static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels if(x >= width) { done = 1; - mcd212_set_vsr(&state->m_mcd212_regs, channel, vsr); + set_vsr(channel, vsr); } } } @@ -1105,46 +1078,44 @@ static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels //mcd212_set_vsr(&state->m_mcd212_regs, channel, vsr); } -static const UINT32 mcd212_4bpp_color[16] = +const UINT32 mcd212_device::s_4bpp_color[16] = { 0x00101010, 0x0010107a, 0x00107a10, 0x00107a7a, 0x007a1010, 0x007a107a, 0x007a7a10, 0x007a7a7a, 0x00101010, 0x001010e6, 0x0010e610, 0x0010e6e6, 0x00e61010, 0x00e610e6, 0x00e6e610, 0x00e6e6e6 }; -static 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) +void 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) { - running_machine &machine = mcd212->machine(); - int x = 0; - UINT8 debug_mode = machine.root_device().ioport("DEBUG")->read(); + UINT8 debug_mode = machine().root_device().ioport("DEBUG")->read(); UINT8 global_plane_a_disable = debug_mode & 1; UINT8 global_plane_b_disable = debug_mode & 2; UINT8 debug_backdrop_enable = debug_mode & 4; UINT8 debug_backdrop_index = debug_mode >> 4; - UINT32 backdrop = debug_backdrop_enable ? mcd212_4bpp_color[debug_backdrop_index] : mcd212_4bpp_color[mcd212->channel[0].backdrop_color]; - UINT8 transparency_mode_a = (mcd212->channel[0].transparency_control >> 0) & 0x0f; - UINT8 transparency_mode_b = (mcd212->channel[0].transparency_control >> 8) & 0x0f; - UINT8 transparent_color_a_r = (UINT8)(mcd212->channel[0].transparent_color_a >> 16); - UINT8 transparent_color_a_g = (UINT8)(mcd212->channel[0].transparent_color_a >> 8); - UINT8 transparent_color_a_b = (UINT8)(mcd212->channel[0].transparent_color_a >> 0); - UINT8 transparent_color_b_r = (UINT8)(mcd212->channel[1].transparent_color_b >> 16); - UINT8 transparent_color_b_g = (UINT8)(mcd212->channel[1].transparent_color_b >> 8); - UINT8 transparent_color_b_b = (UINT8)(mcd212->channel[1].transparent_color_b >> 0); - UINT8 image_coding_method_a = mcd212->channel[0].image_coding_method & 0x0000000f; - UINT8 image_coding_method_b = (mcd212->channel[0].image_coding_method >> 8) & 0x0000000f; - UINT8 dyuv_enable_a = (image_coding_method_a == 5); - UINT8 dyuv_enable_b = (image_coding_method_b == 5); - UINT8 mosaic_enable_a = (mcd212->channel[0].mosaic_hold_a & 0x800000) >> 23; - UINT8 mosaic_enable_b = (mcd212->channel[1].mosaic_hold_b & 0x800000) >> 23; - UINT8 mosaic_count_a = (mcd212->channel[0].mosaic_hold_a & 0x0000ff) << 1; - UINT8 mosaic_count_b = (mcd212->channel[1].mosaic_hold_b & 0x0000ff) << 1; - for(x = 0; x < 768; x++) + UINT32 backdrop = debug_backdrop_enable ? s_4bpp_color[debug_backdrop_index] : s_4bpp_color[m_channel[0].backdrop_color]; + UINT8 transparency_mode_a = (m_channel[0].transparency_control >> 0) & 0x0f; + UINT8 transparency_mode_b = (m_channel[0].transparency_control >> 8) & 0x0f; + UINT8 transparent_color_a_r = (UINT8)(m_channel[0].transparent_color_a >> 16); + UINT8 transparent_color_a_g = (UINT8)(m_channel[0].transparent_color_a >> 8); + UINT8 transparent_color_a_b = (UINT8)(m_channel[0].transparent_color_a >> 0); + UINT8 transparent_color_b_r = (UINT8)(m_channel[1].transparent_color_b >> 16); + UINT8 transparent_color_b_g = (UINT8)(m_channel[1].transparent_color_b >> 8); + UINT8 transparent_color_b_b = (UINT8)(m_channel[1].transparent_color_b >> 0); + UINT8 image_coding_method_a = m_channel[0].image_coding_method & 0x0000000f; + UINT8 image_coding_method_b = (m_channel[0].image_coding_method >> 8) & 0x0000000f; + bool dyuv_enable_a = (image_coding_method_a == 5); + bool dyuv_enable_b = (image_coding_method_b == 5); + UINT8 mosaic_enable_a = (m_channel[0].mosaic_hold_a & 0x800000) >> 23; + UINT8 mosaic_enable_b = (m_channel[1].mosaic_hold_b & 0x800000) >> 23; + UINT8 mosaic_count_a = (m_channel[0].mosaic_hold_a & 0x0000ff) << 1; + UINT8 mosaic_count_b = (m_channel[1].mosaic_hold_b & 0x0000ff) << 1; + for(int x = 0; x < 768; x++) { out[x] = backdrop; - if(!(mcd212->channel[0].transparency_control & MCD212_TCR_DISABLE_MX)) + if(!(m_channel[0].transparency_control & MCD212_TCR_DISABLE_MX)) { - 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); - 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); - 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); + 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); + 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); + 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); out[x] = (abr << 16) | (abg << 8) | abb; } else @@ -1166,16 +1137,16 @@ static void mcd212_mix_lines(mcd212_regs_t *mcd212, UINT8 *plane_a_r, UINT8 *pla 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); break; case 3: - plane_enable_a = !mcd212->region_flag_0[x]; + plane_enable_a = !m_region_flag_0[x]; break; case 4: - plane_enable_a = !mcd212->region_flag_1[x]; + plane_enable_a = !m_region_flag_1[x]; break; case 5: - 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); + 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); break; case 6: - 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); + 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); break; case 8: plane_enable_a = 1; @@ -1184,16 +1155,16 @@ static void mcd212_mix_lines(mcd212_regs_t *mcd212, UINT8 *plane_a_r, UINT8 *pla 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); break; case 11: - plane_enable_a = mcd212->region_flag_0[x]; + plane_enable_a = m_region_flag_0[x]; break; case 12: - plane_enable_a = mcd212->region_flag_1[x]; + plane_enable_a = m_region_flag_1[x]; break; case 13: - 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; + 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; break; case 14: - 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; + 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; break; default: verboselog(machine, 0, "Unhandled transparency mode for plane A: %d\n", transparency_mode_a); @@ -1209,16 +1180,16 @@ static void mcd212_mix_lines(mcd212_regs_t *mcd212, UINT8 *plane_a_r, UINT8 *pla 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); break; case 3: - plane_enable_b = !mcd212->region_flag_0[x]; + plane_enable_b = !m_region_flag_0[x]; break; case 4: - plane_enable_b = !mcd212->region_flag_1[x]; + plane_enable_b = !m_region_flag_1[x]; break; case 5: - 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); + 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); break; case 6: - 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); + 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); break; case 8: plane_enable_b = 1; @@ -1227,16 +1198,16 @@ static void mcd212_mix_lines(mcd212_regs_t *mcd212, UINT8 *plane_a_r, UINT8 *pla 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); break; case 11: - plane_enable_b = mcd212->region_flag_0[x]; + plane_enable_b = m_region_flag_0[x]; break; case 12: - plane_enable_b = mcd212->region_flag_1[x]; + plane_enable_b = m_region_flag_1[x]; break; case 13: - 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; + 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; break; case 14: - 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; + 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; break; default: verboselog(machine, 0, "Unhandled transparency mode for plane B: %d\n", transparency_mode_b); @@ -1251,13 +1222,13 @@ static void mcd212_mix_lines(mcd212_regs_t *mcd212, UINT8 *plane_a_r, UINT8 *pla { plane_enable_b = 0; } - plane_a_r_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_r_cur - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + 16); - plane_a_g_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_g_cur - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + 16); - plane_a_b_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_b_cur - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + 16); - plane_b_r_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_r_cur - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16); - plane_b_g_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_g_cur - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16); - plane_b_b_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_b_cur - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16); - switch(mcd212->channel[0].plane_order) + plane_a_r_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_r_cur - 16) * m_channel[0].weight_factor_a[x]) >> 6) + 16); + plane_a_g_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_g_cur - 16) * m_channel[0].weight_factor_a[x]) >> 6) + 16); + plane_a_b_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_b_cur - 16) * m_channel[0].weight_factor_a[x]) >> 6) + 16); + plane_b_r_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_r_cur - 16) * m_channel[1].weight_factor_b[x]) >> 6) + 16); + plane_b_g_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_g_cur - 16) * m_channel[1].weight_factor_b[x]) >> 6) + 16); + plane_b_b_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_b_cur - 16) * m_channel[1].weight_factor_b[x]) >> 6) + 16); + switch(m_channel[0].plane_order) { case MCD212_POR_AB: if(plane_enable_a) @@ -1284,22 +1255,21 @@ static void mcd212_mix_lines(mcd212_regs_t *mcd212, UINT8 *plane_a_r, UINT8 *pla } } -static void mcd212_draw_cursor(mcd212_regs_t *mcd212, UINT32 *scanline, int y) +void mcd212_device::draw_cursor(UINT32 *scanline, int y) { - if(mcd212->channel[0].cursor_control & MCD212_CURCNT_EN) + if(m_channel[0].cursor_control & MCD212_CURCNT_EN) { - UINT16 curx = mcd212->channel[0].cursor_position & 0x3ff; - UINT16 cury = ((mcd212->channel[0].cursor_position >> 12) & 0x3ff) + 22; - UINT32 x = 0; + UINT16 curx = m_channel[0].cursor_position & 0x3ff; + UINT16 cury = ((m_channel[0].cursor_position >> 12) & 0x3ff) + 22; if(y >= cury && y < (cury + 16)) { - UINT32 color = mcd212_4bpp_color[mcd212->channel[0].cursor_control & MCD212_CURCNT_COLOR]; + UINT32 color = s_4bpp_color[m_channel[0].cursor_control & MCD212_CURCNT_COLOR]; y -= cury; - if(mcd212->channel[0].cursor_control & MCD212_CURCNT_CUW) + if(m_channel[0].cursor_control & MCD212_CURCNT_CUW) { - for(x = curx; x < curx + 64 && x < 768; x++) + for(int x = curx; x < curx + 64 && x < 768; x++) { - if(mcd212->channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 2)))) + if(m_channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 2)))) { scanline[(x++)/2] = color; scanline[(x++)/2] = color; @@ -1313,48 +1283,43 @@ static void mcd212_draw_cursor(mcd212_regs_t *mcd212, UINT32 *scanline, int y) } else { - for(x = curx; x < curx + 32 && x < 768; x++) + for(int x = curx; x < curx + 32 && x < 768; x++) { - if(mcd212->channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 1)))) + if(m_channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 1)))) { scanline[(x++)/2] = color; scanline[x/2] = color; } - else - { - } } } } } } -static void mcd212_draw_scanline(mcd212_regs_t *mcd212, int y) +void mcd212_device::draw_scanline(int y) { - bitmap_rgb32 &bitmap = mcd212->m_bitmap; UINT8 plane_a_r[768], plane_a_g[768], plane_a_b[768]; UINT8 plane_b_r[768], plane_b_g[768], plane_b_b[768]; UINT32 out[768]; - UINT32 *scanline = &bitmap.pix32(y); + UINT32 *scanline = &m_bitmap.pix32(y); int x; - mcd212_process_vsr(mcd212, 0, plane_a_r, plane_a_g, plane_a_b); - mcd212_process_vsr(mcd212, 1, plane_b_r, plane_b_g, plane_b_b); + process_vsr(0, plane_a_r, plane_a_g, plane_a_b); + process_vsr(1, plane_b_r, plane_b_g, plane_b_b); - mcd212_mix_lines(mcd212, plane_a_r, plane_a_g, plane_a_b, plane_b_r, plane_b_g, plane_b_b, out); + mix_lines(plane_a_r, plane_a_g, plane_a_b, plane_b_r, plane_b_g, plane_b_b, out); for(x = 0; x < 384; x++) { scanline[x] = out[x*2]; } - mcd212_draw_cursor(mcd212, scanline, y); + draw_cursor(scanline, y); } -READ16_HANDLER( mcd212_r ) +READ16_MEMBER( mcd212_device::regs_r ) { - cdi_state *state = space.machine().driver_data(); - mcd212_regs_t *mcd212 = &state->m_mcd212_regs; + cdi_state *state = machine().driver_data(); UINT8 channel = 1 - (offset / 8); switch(offset) @@ -1363,17 +1328,17 @@ READ16_HANDLER( mcd212_r ) case 0x10/2: if(ACCESSING_BITS_0_7) { - verboselog(space.machine(), 12, "mcd212_r: Status Register %d: %02x & %04x\n", channel + 1, mcd212->channel[1 - (offset / 8)].csrr, mem_mask); + verboselog(machine(), 12, "mcd212_r: Status Register %d: %02x & %04x\n", channel + 1, m_channel[1 - (offset / 8)].csrr, mem_mask); if(channel == 0) { - return mcd212->channel[0].csrr; + return m_channel[0].csrr; } else { - UINT8 old_csr = mcd212->channel[1].csrr; + UINT8 old_csr = m_channel[1].csrr; UINT8 interrupt1 = (state->m_scc->get_lir() >> 4) & 7; //UINT8 interrupt2 = state->m_scc68070_regs.lir & 7; - mcd212->channel[1].csrr &= ~(MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2); + m_channel[1].csrr &= ~(MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2); if(interrupt1) { state->m_maincpu->set_input_line(M68K_IRQ_1 + (interrupt1 - 1), CLEAR_LINE); @@ -1387,273 +1352,276 @@ READ16_HANDLER( mcd212_r ) } else { - verboselog(space.machine(), 2, "mcd212_r: Unknown Register %d: %04x\n", channel + 1, mem_mask); + verboselog(machine(), 2, "mcd212_r: Unknown Register %d: %04x\n", channel + 1, mem_mask); } break; case 0x02/2: case 0x12/2: - 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); - return mcd212->channel[1 - (offset / 8)].dcr; + verboselog(machine(), 2, "mcd212_r: Display Command Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, m_channel[1 - (offset / 8)].dcr, mem_mask); + return m_channel[1 - (offset / 8)].dcr; case 0x04/2: case 0x14/2: - 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); - return mcd212->channel[1 - (offset / 8)].vsr; + verboselog(machine(), 2, "mcd212_r: Video Start Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, m_channel[1 - (offset / 8)].vsr, mem_mask); + return m_channel[1 - (offset / 8)].vsr; case 0x08/2: case 0x18/2: - 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); - return mcd212->channel[1 - (offset / 8)].ddr; + verboselog(machine(), 2, "mcd212_r: Display Decoder Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, m_channel[1 - (offset / 8)].ddr, mem_mask); + return m_channel[1 - (offset / 8)].ddr; case 0x0a/2: case 0x1a/2: - 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); - return mcd212->channel[1 - (offset / 8)].dcp; + verboselog(machine(), 2, "mcd212_r: DCA Pointer Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, m_channel[1 - (offset / 8)].dcp, mem_mask); + return m_channel[1 - (offset / 8)].dcp; default: - verboselog(space.machine(), 2, "mcd212_r: Unknown Register %d & %04x\n", (1 - (offset / 8)) + 1, mem_mask); + verboselog(machine(), 2, "mcd212_r: Unknown Register %d & %04x\n", (1 - (offset / 8)) + 1, mem_mask); break; } return 0; } -WRITE16_HANDLER( mcd212_w ) +WRITE16_MEMBER( mcd212_device::regs_w ) { - cdi_state *state = space.machine().driver_data(); - mcd212_regs_t *mcd212 = &state->m_mcd212_regs; - switch(offset) { case 0x00/2: case 0x10/2: - verboselog(space.machine(), 2, "mcd212_w: Status Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); - COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].csrw); - mcd212_update_visible_area(space.machine()); + verboselog(machine(), 2, "mcd212_w: Status Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); + COMBINE_DATA(&m_channel[1 - (offset / 8)].csrw); + update_visible_area(); break; case 0x02/2: case 0x12/2: - verboselog(space.machine(), 2, "mcd212_w: Display Command Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); - COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].dcr); - mcd212_update_visible_area(space.machine()); + verboselog(machine(), 2, "mcd212_w: Display Command Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); + COMBINE_DATA(&m_channel[1 - (offset / 8)].dcr); + update_visible_area(); break; case 0x04/2: case 0x14/2: - verboselog(space.machine(), 2, "mcd212_w: Video Start Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); - COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].vsr); + verboselog(machine(), 2, "mcd212_w: Video Start Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); + COMBINE_DATA(&m_channel[1 - (offset / 8)].vsr); break; case 0x08/2: case 0x18/2: - verboselog(space.machine(), 2, "mcd212_w: Display Decoder Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); - COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].ddr); + verboselog(machine(), 2, "mcd212_w: Display Decoder Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); + COMBINE_DATA(&m_channel[1 - (offset / 8)].ddr); break; case 0x0a/2: case 0x1a/2: - verboselog(space.machine(), 2, "mcd212_w: DCA Pointer Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); - COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].dcp); + verboselog(machine(), 2, "mcd212_w: DCA Pointer Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); + COMBINE_DATA(&m_channel[1 - (offset / 8)].dcp); break; default: - verboselog(space.machine(), 2, "mcd212_w: Unknown Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); + verboselog(machine(), 2, "mcd212_w: Unknown Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); break; } } -TIMER_CALLBACK( mcd212_perform_scan ) +TIMER_CALLBACK_MEMBER( mcd212_device::perform_scan ) { - cdi_state *state = machine.driver_data(); - mcd212_regs_t *mcd212 = &state->m_mcd212_regs; - int scanline = machine.primary_screen->vpos(); + int scanline = machine().primary_screen->vpos(); - if(/*mcd212->channel[0].dcr & MCD212_DCR_DE*/1) + if(1) { if(scanline == 0) { // Process ICA - int index = 0; verboselog(machine, 6, "Frame Start\n" ); - mcd212->channel[0].csrr &= 0x7f; - for(index = 0; index < 2; index++) + m_channel[0].csrr &= 0x7f; + for(int index = 0; index < 2; index++) { - if(mcd212->channel[index].dcr & MCD212_DCR_ICA) + if(m_channel[index].dcr & MCD212_DCR_ICA) { - mcd212_process_ica(mcd212, index); + process_ica(index); } } - cdi220_draw_lcd(machine, scanline); + draw_lcd(scanline); } else if(scanline < 22) { - cdi220_draw_lcd(machine, scanline); + draw_lcd(scanline); } else if(scanline >= 22) { - int index = 0; - mcd212->channel[0].csrr |= 0x80; + m_channel[0].csrr |= 0x80; // Process VSR - mcd212_draw_scanline(mcd212, scanline); + draw_scanline(scanline); // Process DCA - for(index = 0; index < 2; index++) + for(int index = 0; index < 2; index++) { - if(mcd212->channel[index].dcr & MCD212_DCR_DCA) + if(m_channel[index].dcr & MCD212_DCR_DCA) { if(scanline == 22) { - mcd212->channel[index].dca = mcd212_get_dcp(mcd212, index); + m_channel[index].dca = get_dcp(index); } - mcd212_process_dca(mcd212, index); + process_dca(index); } } if(scanline == 301) { - mcd212->channel[0].csrr ^= 0x20; + m_channel[0].csrr ^= 0x20; } } } - mcd212->scan_timer->adjust(machine.primary_screen->time_until_pos(( scanline + 1 ) % 302, 0)); + m_scan_timer->adjust(machine().primary_screen->time_until_pos(( scanline + 1 ) % 302, 0)); } -void mcd212_init(running_machine &machine, mcd212_regs_t *mcd212) +void mcd212_device::device_reset() { - mcd212->m_machine = &machine; - machine.primary_screen->register_screen_bitmap(mcd212->m_bitmap); - - int index = 0; - for(index = 0; index < 2; index++) + for(int index = 0; index < 2; index++) { - mcd212->channel[index].csrr = 0; - mcd212->channel[index].csrw = 0; - mcd212->channel[index].dcr = 0; - mcd212->channel[index].vsr = 0; - mcd212->channel[index].ddr = 0; - mcd212->channel[index].dcp = 0; - mcd212->channel[index].dca = 0; - memset(mcd212->channel[index].clut_r, 0, 256); - memset(mcd212->channel[index].clut_g, 0, 256); - memset(mcd212->channel[index].clut_b, 0, 256); - mcd212->channel[index].image_coding_method = 0; - mcd212->channel[index].transparency_control = 0; - mcd212->channel[index].plane_order = 0; - mcd212->channel[index].clut_bank = 0; - mcd212->channel[index].transparent_color_a = 0; - mcd212->channel[index].transparent_color_b = 0; - mcd212->channel[index].mask_color_a = 0; - mcd212->channel[index].mask_color_b = 0; - mcd212->channel[index].dyuv_abs_start_a = 0; - mcd212->channel[index].dyuv_abs_start_b = 0; - mcd212->channel[index].cursor_position = 0; - mcd212->channel[index].cursor_control = 0; - memset((UINT8*)&mcd212->channel[index].cursor_pattern, 0, 16 * sizeof(UINT32)); - memset((UINT8*)&mcd212->channel[index].region_control, 0, 8 * sizeof(UINT32)); - mcd212->channel[index].backdrop_color = 0; - mcd212->channel[index].mosaic_hold_a = 0; - mcd212->channel[index].mosaic_hold_b = 0; - memset(mcd212->channel[index].weight_factor_a, 0, 768); - memset(mcd212->channel[index].weight_factor_b, 0, 768); + m_channel[index].csrr = 0; + m_channel[index].csrw = 0; + m_channel[index].dcr = 0; + m_channel[index].vsr = 0; + m_channel[index].ddr = 0; + m_channel[index].dcp = 0; + m_channel[index].dca = 0; + memset(m_channel[index].clut_r, 0, 256); + memset(m_channel[index].clut_g, 0, 256); + memset(m_channel[index].clut_b, 0, 256); + m_channel[index].image_coding_method = 0; + m_channel[index].transparency_control = 0; + m_channel[index].plane_order = 0; + m_channel[index].clut_bank = 0; + m_channel[index].transparent_color_a = 0; + m_channel[index].transparent_color_b = 0; + m_channel[index].mask_color_a = 0; + m_channel[index].mask_color_b = 0; + m_channel[index].dyuv_abs_start_a = 0; + m_channel[index].dyuv_abs_start_b = 0; + m_channel[index].cursor_position = 0; + m_channel[index].cursor_control = 0; + memset((UINT8*)&m_channel[index].cursor_pattern, 0, 16 * sizeof(UINT32)); + memset((UINT8*)&m_channel[index].region_control, 0, 8 * sizeof(UINT32)); + m_channel[index].backdrop_color = 0; + m_channel[index].mosaic_hold_a = 0; + m_channel[index].mosaic_hold_b = 0; + memset(m_channel[index].weight_factor_a, 0, 768); + memset(m_channel[index].weight_factor_b, 0, 768); } - memset(mcd212->region_flag_0, 0, 768); - memset(mcd212->region_flag_1, 0, 768); - - state_save_register_global_array(machine, mcd212->region_flag_0); - state_save_register_global_array(machine, mcd212->region_flag_1); - state_save_register_global(machine, mcd212->channel[0].csrr); - state_save_register_global(machine, mcd212->channel[0].csrw); - state_save_register_global(machine, mcd212->channel[0].dcr); - state_save_register_global(machine, mcd212->channel[0].vsr); - state_save_register_global(machine, mcd212->channel[0].ddr); - state_save_register_global(machine, mcd212->channel[0].dcp); - state_save_register_global(machine, mcd212->channel[0].dca); - state_save_register_global_array(machine, mcd212->channel[0].clut_r); - state_save_register_global_array(machine, mcd212->channel[0].clut_g); - state_save_register_global_array(machine, mcd212->channel[0].clut_b); - state_save_register_global(machine, mcd212->channel[0].image_coding_method); - state_save_register_global(machine, mcd212->channel[0].transparency_control); - state_save_register_global(machine, mcd212->channel[0].plane_order); - state_save_register_global(machine, mcd212->channel[0].clut_bank); - state_save_register_global(machine, mcd212->channel[0].transparent_color_a); - state_save_register_global(machine, mcd212->channel[0].transparent_color_b); - state_save_register_global(machine, mcd212->channel[0].mask_color_a); - state_save_register_global(machine, mcd212->channel[0].mask_color_b); - state_save_register_global(machine, mcd212->channel[0].dyuv_abs_start_a); - state_save_register_global(machine, mcd212->channel[0].dyuv_abs_start_b); - state_save_register_global(machine, mcd212->channel[0].cursor_position); - state_save_register_global(machine, mcd212->channel[0].cursor_control); - state_save_register_global_array(machine, mcd212->channel[0].cursor_pattern); - state_save_register_global_array(machine, mcd212->channel[0].region_control); - state_save_register_global(machine, mcd212->channel[0].backdrop_color); - state_save_register_global(machine, mcd212->channel[0].mosaic_hold_a); - state_save_register_global(machine, mcd212->channel[0].mosaic_hold_b); - state_save_register_global_array(machine, mcd212->channel[0].weight_factor_a); - state_save_register_global_array(machine, mcd212->channel[0].weight_factor_b); - state_save_register_global(machine, mcd212->channel[1].csrr); - state_save_register_global(machine, mcd212->channel[1].csrw); - state_save_register_global(machine, mcd212->channel[1].dcr); - state_save_register_global(machine, mcd212->channel[1].vsr); - state_save_register_global(machine, mcd212->channel[1].ddr); - state_save_register_global(machine, mcd212->channel[1].dcp); - state_save_register_global(machine, mcd212->channel[1].dca); - state_save_register_global_array(machine, mcd212->channel[1].clut_r); - state_save_register_global_array(machine, mcd212->channel[1].clut_g); - state_save_register_global_array(machine, mcd212->channel[1].clut_b); - state_save_register_global(machine, mcd212->channel[1].image_coding_method); - state_save_register_global(machine, mcd212->channel[1].transparency_control); - state_save_register_global(machine, mcd212->channel[1].plane_order); - state_save_register_global(machine, mcd212->channel[1].clut_bank); - state_save_register_global(machine, mcd212->channel[1].transparent_color_a); - state_save_register_global(machine, mcd212->channel[1].transparent_color_b); - state_save_register_global(machine, mcd212->channel[1].mask_color_a); - state_save_register_global(machine, mcd212->channel[1].mask_color_b); - state_save_register_global(machine, mcd212->channel[1].dyuv_abs_start_a); - state_save_register_global(machine, mcd212->channel[1].dyuv_abs_start_b); - state_save_register_global(machine, mcd212->channel[1].cursor_position); - state_save_register_global(machine, mcd212->channel[1].cursor_control); - state_save_register_global_array(machine, mcd212->channel[1].cursor_pattern); - state_save_register_global_array(machine, mcd212->channel[1].region_control); - state_save_register_global(machine, mcd212->channel[1].backdrop_color); - state_save_register_global(machine, mcd212->channel[1].mosaic_hold_a); - state_save_register_global(machine, mcd212->channel[1].mosaic_hold_b); - state_save_register_global_array(machine, mcd212->channel[1].weight_factor_a); - state_save_register_global_array(machine, mcd212->channel[1].weight_factor_b); + memset(m_region_flag_0, 0, 768); + memset(m_region_flag_1, 0, 768); } -void mcd212_ab_init(mcd212_ab_t *mcd212_ab) -{ - WORD68K w = 0; - SWORD68K sw = 0; - WORD68K d = 0; +//------------------------------------------------- +// mcd212_device - constructor +//------------------------------------------------- - //* Delta decoding array. - static const BYTE68K mcd212_abDelta[16] = { 0, 1, 4, 9, 16, 27, 44, 79, 128, 177, 212, 229, 240, 247, 252, 255 }; +mcd212_device::mcd212_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, MACHINE_MCD212, "MCD212", tag, owner, clock) +{ +} + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void mcd212_device::device_start() +{ + machine().primary_screen->register_screen_bitmap(m_bitmap); + + m_scan_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mcd212_device::perform_scan), this)); + m_scan_timer->adjust(machine().primary_screen->time_until_pos(0, 0)); + + save_item(NAME(m_region_flag_0)); + save_item(NAME(m_region_flag_1)); + save_item(NAME(m_channel[0].csrr)); + save_item(NAME(m_channel[0].csrw)); + save_item(NAME(m_channel[0].dcr)); + save_item(NAME(m_channel[0].vsr)); + save_item(NAME(m_channel[0].ddr)); + save_item(NAME(m_channel[0].dcp)); + save_item(NAME(m_channel[0].dca)); + save_item(NAME(m_channel[0].clut_r)); + save_item(NAME(m_channel[0].clut_g)); + save_item(NAME(m_channel[0].clut_b)); + save_item(NAME(m_channel[0].image_coding_method)); + save_item(NAME(m_channel[0].transparency_control)); + save_item(NAME(m_channel[0].plane_order)); + save_item(NAME(m_channel[0].clut_bank)); + save_item(NAME(m_channel[0].transparent_color_a)); + save_item(NAME(m_channel[0].transparent_color_b)); + save_item(NAME(m_channel[0].mask_color_a)); + save_item(NAME(m_channel[0].mask_color_b)); + save_item(NAME(m_channel[0].dyuv_abs_start_a)); + save_item(NAME(m_channel[0].dyuv_abs_start_b)); + save_item(NAME(m_channel[0].cursor_position)); + save_item(NAME(m_channel[0].cursor_control)); + save_item(NAME(m_channel[0].cursor_pattern)); + save_item(NAME(m_channel[0].region_control)); + save_item(NAME(m_channel[0].backdrop_color)); + save_item(NAME(m_channel[0].mosaic_hold_a)); + save_item(NAME(m_channel[0].mosaic_hold_b)); + save_item(NAME(m_channel[0].weight_factor_a)); + save_item(NAME(m_channel[0].weight_factor_b)); + save_item(NAME(m_channel[1].csrr)); + save_item(NAME(m_channel[1].csrw)); + save_item(NAME(m_channel[1].dcr)); + save_item(NAME(m_channel[1].vsr)); + save_item(NAME(m_channel[1].ddr)); + save_item(NAME(m_channel[1].dcp)); + save_item(NAME(m_channel[1].dca)); + save_item(NAME(m_channel[1].clut_r)); + save_item(NAME(m_channel[1].clut_g)); + save_item(NAME(m_channel[1].clut_b)); + save_item(NAME(m_channel[1].image_coding_method)); + save_item(NAME(m_channel[1].transparency_control)); + save_item(NAME(m_channel[1].plane_order)); + save_item(NAME(m_channel[1].clut_bank)); + save_item(NAME(m_channel[1].transparent_color_a)); + save_item(NAME(m_channel[1].transparent_color_b)); + save_item(NAME(m_channel[1].mask_color_a)); + save_item(NAME(m_channel[1].mask_color_b)); + save_item(NAME(m_channel[1].dyuv_abs_start_a)); + save_item(NAME(m_channel[1].dyuv_abs_start_b)); + save_item(NAME(m_channel[1].cursor_position)); + save_item(NAME(m_channel[1].cursor_control)); + save_item(NAME(m_channel[1].cursor_pattern)); + save_item(NAME(m_channel[1].region_control)); + save_item(NAME(m_channel[1].backdrop_color)); + save_item(NAME(m_channel[1].mosaic_hold_a)); + save_item(NAME(m_channel[1].mosaic_hold_b)); + save_item(NAME(m_channel[1].weight_factor_a)); + save_item(NAME(m_channel[1].weight_factor_b)); +} + +void mcd212_device::ab_init() +{ + // Delta decoding array. + static const BYTE68K abDelta[16] = { 0, 1, 4, 9, 16, 27, 44, 79, 128, 177, 212, 229, 240, 247, 252, 255 }; // Initialize delta decoding arrays for each unsigned byte value b. - for (d = 0; d < BYTE68K_MAX + 1; d++) + for (WORD68K d = 0; d < BYTE68K_MAX + 1; d++) { - mcd212_ab->deltaY[d] = mcd212_abDelta[d & 15]; + m_ab.deltaY[d] = abDelta[d & 15]; } // Initialize delta decoding arrays for each unsigned byte value b. - for (d = 0; d < (BYTE68K_MAX + 1); d++) + for (WORD68K d = 0; d < (BYTE68K_MAX + 1); d++) { - mcd212_ab->deltaUV[d] = mcd212_abDelta[d >> 4]; + m_ab.deltaUV[d] = abDelta[d >> 4]; } // Initialize color limit and clamp arrays. - for (w = 0; w < 3 * BYTE68K_MAX; w++) + for (WORD68K w = 0; w < 3 * BYTE68K_MAX; w++) { - mcd212_ab->limit[w] = (w < BYTE68K_MAX + 16) ? 0 : w <= 16 + 2 * BYTE68K_MAX ? w - BYTE68K_MAX - 16 : BYTE68K_MAX; - mcd212_ab->clamp[w] = (w < BYTE68K_MAX + 32) ? 16 : w <= 16 + 2 * BYTE68K_MAX ? w - BYTE68K_MAX - 16 : BYTE68K_MAX; + m_ab.limit[w] = (w < BYTE68K_MAX + 16) ? 0 : w <= 16 + 2 * BYTE68K_MAX ? w - BYTE68K_MAX - 16 : BYTE68K_MAX; + m_ab.clamp[w] = (w < BYTE68K_MAX + 32) ? 16 : w <= 16 + 2 * BYTE68K_MAX ? w - BYTE68K_MAX - 16 : BYTE68K_MAX; } - for (sw = 0; sw < 0x100; sw++) + for (SWORD68K sw = 0; sw < 0x100; sw++) { - mcd212_ab->matrixUB[sw] = (444 * (sw - 128)) / 256; - mcd212_ab->matrixUG[sw] = - (86 * (sw - 128)) / 256; - mcd212_ab->matrixVG[sw] = - (179 * (sw - 128)) / 256; - mcd212_ab->matrixVR[sw] = (351 * (sw - 128)) / 256; + m_ab.matrixUB[sw] = (444 * (sw - 128)) / 256; + m_ab.matrixUG[sw] = - (86 * (sw - 128)) / 256; + m_ab.matrixVG[sw] = - (179 * (sw - 128)) / 256; + m_ab.matrixVR[sw] = (351 * (sw - 128)) / 256; } } void cdi_state::video_start() { - mcd212_ab_init(&m_mcd212_ab); - mcd212_init(machine(), &m_mcd212_regs); - m_mcd212_regs.scan_timer = machine().scheduler().timer_alloc(FUNC(mcd212_perform_scan)); - m_mcd212_regs.scan_timer->adjust(machine().primary_screen->time_until_pos(0, 0)); + m_mcd212->ab_init(); screen_device *screen = downcast(machine().device("lcd")); screen->register_screen_bitmap(m_lcdbitmap); @@ -1661,7 +1629,7 @@ void cdi_state::video_start() UINT32 cdi_state::screen_update_cdimono1(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) { - copybitmap(bitmap, m_mcd212_regs.m_bitmap, 0, 0, 0, 0, cliprect); + copybitmap(bitmap, m_mcd212->get_bitmap(), 0, 0, 0, 0, cliprect); return 0; } diff --git a/src/mame/video/mcd212.h b/src/mame/video/mcd212.h index de6a7cedea4..b08beaebcc9 100644 --- a/src/mame/video/mcd212.h +++ b/src/mame/video/mcd212.h @@ -24,55 +24,6 @@ TODO: #include "emu.h" -struct mcd212_channel_t -{ - UINT8 csrr; - UINT16 csrw; - UINT16 dcr; - UINT16 vsr; - UINT16 ddr; - UINT16 dcp; - UINT32 dca; - UINT8 clut_r[256]; - UINT8 clut_g[256]; - UINT8 clut_b[256]; - UINT32 image_coding_method; - UINT32 transparency_control; - UINT32 plane_order; - UINT32 clut_bank; - UINT32 transparent_color_a; - UINT32 reserved0; - UINT32 transparent_color_b; - UINT32 mask_color_a; - UINT32 reserved1; - UINT32 mask_color_b; - UINT32 dyuv_abs_start_a; - UINT32 dyuv_abs_start_b; - UINT32 reserved2; - UINT32 cursor_position; - UINT32 cursor_control; - UINT32 cursor_pattern[16]; - UINT32 region_control[8]; - UINT32 backdrop_color; - UINT32 mosaic_hold_a; - UINT32 mosaic_hold_b; - UINT8 weight_factor_a[768]; - UINT8 weight_factor_b[768]; -}; - -struct mcd212_regs_t -{ - running_machine &machine() const { assert(m_machine != NULL); return *m_machine; } - - mcd212_channel_t channel[2]; - emu_timer *scan_timer; - UINT8 region_flag_0[768]; - UINT8 region_flag_1[768]; - - running_machine *m_machine; - bitmap_rgb32 m_bitmap; -}; - #define MCD212_CURCNT_COLOR 0x00000f // Cursor color #define MCD212_CURCNT_CUW 0x008000 // Cursor width #define MCD212_CURCNT_COF 0x070000 // Cursor off time @@ -155,41 +106,145 @@ typedef INT16 SWORD68K; #define BYTE68K_MAX 255 +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** + +#define MCFG_MCD212_ADD(_tag) \ + MCFG_DEVICE_ADD(_tag, MACHINE_MCD212, 0) +#define MCFG_MCD212_REPLACE(_tag) \ + MCFG_DEVICE_REPLACE(_tag, MACHINE_MCD212, 0) -struct mcd212_ab_t +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> mcd212_device + +class mcd212_device : public device_t { - //* Color limit array. - BYTE68K limit[3 * BYTE68K_MAX]; +public: + // construction/destruction + mcd212_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - //* Color clamp array. - BYTE68K clamp[3 * BYTE68K_MAX]; + // device members + DECLARE_READ16_MEMBER( regs_r ); + DECLARE_WRITE16_MEMBER( regs_w ); + TIMER_CALLBACK_MEMBER( perform_scan ); - //* U-to-B matrix array. - SWORD68K matrixUB[BYTE68K_MAX + 1]; + void ab_init(); - //* U-to-G matrix array. - SWORD68K matrixUG[BYTE68K_MAX + 1]; + bitmap_rgb32& get_bitmap() { return m_bitmap; } - //* V-to-G matrix array. - SWORD68K matrixVG[BYTE68K_MAX + 1]; + struct channel_t + { + UINT8 csrr; + UINT16 csrw; + UINT16 dcr; + UINT16 vsr; + UINT16 ddr; + UINT16 dcp; + UINT32 dca; + UINT8 clut_r[256]; + UINT8 clut_g[256]; + UINT8 clut_b[256]; + UINT32 image_coding_method; + UINT32 transparency_control; + UINT32 plane_order; + UINT32 clut_bank; + UINT32 transparent_color_a; + UINT32 reserved0; + UINT32 transparent_color_b; + UINT32 mask_color_a; + UINT32 reserved1; + UINT32 mask_color_b; + UINT32 dyuv_abs_start_a; + UINT32 dyuv_abs_start_b; + UINT32 reserved2; + UINT32 cursor_position; + UINT32 cursor_control; + UINT32 cursor_pattern[16]; + UINT32 region_control[8]; + UINT32 backdrop_color; + UINT32 mosaic_hold_a; + UINT32 mosaic_hold_b; + UINT8 weight_factor_a[768]; + UINT8 weight_factor_b[768]; + }; - //* V-to-R matrix array. - SWORD68K matrixVR[BYTE68K_MAX + 1]; + struct ab_t + { + //* Color limit array. + BYTE68K limit[3 * BYTE68K_MAX]; - //* Delta-Y decoding array. - BYTE68K deltaY[BYTE68K_MAX + 1]; + //* Color clamp array. + BYTE68K clamp[3 * BYTE68K_MAX]; - //* Delta-U/V decoding array. - BYTE68K deltaUV[BYTE68K_MAX + 1]; + //* U-to-B matrix array. + SWORD68K matrixUB[BYTE68K_MAX + 1]; + + //* U-to-G matrix array. + SWORD68K matrixUG[BYTE68K_MAX + 1]; + + //* V-to-G matrix array. + SWORD68K matrixVG[BYTE68K_MAX + 1]; + + //* V-to-R matrix array. + SWORD68K matrixVR[BYTE68K_MAX + 1]; + + //* Delta-Y decoding array. + BYTE68K deltaY[BYTE68K_MAX + 1]; + + //* Delta-U/V decoding array. + BYTE68K deltaUV[BYTE68K_MAX + 1]; + }; + +protected: + // device-level overrides + virtual void device_start(); + virtual void device_reset(); + +private: + // internal state + channel_t m_channel[2]; + emu_timer *m_scan_timer; + UINT8 m_region_flag_0[768]; + UINT8 m_region_flag_1[768]; + + bitmap_rgb32 m_bitmap; + + static const UINT32 s_4bpp_color[16]; + + ab_t m_ab; + + void update_region_arrays(); + + void set_vsr(int channel, UINT32 value); + UINT32 get_vsr(int channel); + + void set_dcp(int channel, UINT32 value); + UINT32 get_dcp(int channel); + + void set_display_parameters(int channel, UINT8 value); + void update_visible_area(); + UINT32 get_screen_width(); + + void process_ica(int channel); + void process_dca(int channel); + void process_vsr(int channel, UINT8 *pixels_r, UINT8 *pixels_g, UINT8 *pixels_b); + + void set_register(int channel, UINT8 reg, UINT32 value); + + 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); + + void draw_cursor(UINT32 *scanline, int y); + void draw_scanline(int y); + + void draw_lcd(int y); }; -// Member functions -DECLARE_READ16_HANDLER( mcd212_r ); -DECLARE_WRITE16_HANDLER( mcd212_w ); -TIMER_CALLBACK( mcd212_perform_scan ); -VIDEO_START( cdimono1 ); -SCREEN_UPDATE_RGB32( cdimono1 ); -SCREEN_UPDATE_RGB32( cdimono1_lcd ); +// device type definition +extern const device_type MACHINE_MCD212; #endif // _VIDEO_MCD212_H_