From 74a324d6320d02af6e85e087b8966b527e567d78 Mon Sep 17 00:00:00 2001 From: Scott Stone Date: Thu, 16 Aug 2012 21:38:45 +0000 Subject: [PATCH] killed off the ancient vdp implementation so we're all using the current one now, also made c2 manage it's own palette instead of having the vdp do it for it, might need a bit of tweaking but it works. From Haze (nw) --- src/mame/drivers/segac2.c | 83 ++- src/mame/drivers/segas18.c | 51 +- src/mame/includes/genesis.h | 14 +- src/mame/includes/megadriv.h | 6 +- src/mame/includes/segas18.h | 7 + src/mame/machine/megavdp.c | 118 +-- src/mame/machine/megavdp.h | 16 + src/mame/video/genesis.c | 1309 +--------------------------------- src/mame/video/segas18.c | 37 +- 9 files changed, 236 insertions(+), 1405 deletions(-) diff --git a/src/mame/drivers/segac2.c b/src/mame/drivers/segac2.c index f2b426aecc0..af07e44acb2 100644 --- a/src/mame/drivers/segac2.c +++ b/src/mame/drivers/segac2.c @@ -88,6 +88,8 @@ #define LOG_PALETTE 0 #define LOG_IOCHIP 0 +int segac2_bg_pal_lookup[4]; +int segac2_sp_pal_lookup[4]; static void recompute_palette_tables( running_machine &machine ); @@ -113,12 +115,20 @@ static MACHINE_START( segac2 ) static MACHINE_RESET( segac2 ) { segac2_state *state = machine.driver_data(); - megadriv_framerate = 60; +// megadriv_framerate = 60; // megadriv_scanline_timer = machine.device("md_scan_timer"); // megadriv_scanline_timer->adjust(attotime::zero); + segac2_bg_pal_lookup[0] = 0x00; + segac2_bg_pal_lookup[1] = 0x10; + segac2_bg_pal_lookup[2] = 0x20; + segac2_bg_pal_lookup[3] = 0x30; + segac2_sp_pal_lookup[0] = 0x00; + segac2_sp_pal_lookup[1] = 0x10; + segac2_sp_pal_lookup[2] = 0x20; + segac2_sp_pal_lookup[3] = 0x30; megadriv_reset_vdp(machine); @@ -226,19 +236,19 @@ static WRITE16_HANDLER( palette_w ) /* set the color */ palette_set_color_rgb(space->machine(), offset, pal5bit(r), pal5bit(g), pal5bit(b)); - megadrive_vdp_palette_lookup[offset] = (b) | (g << 5) | (r << 10); - megadrive_vdp_palette_lookup_sprite[offset] = (b) | (g << 5) | (r << 10); +// megadrive_vdp_palette_lookup[offset] = (b) | (g << 5) | (r << 10); +// megadrive_vdp_palette_lookup_sprite[offset] = (b) | (g << 5) | (r << 10); tmpr = r >> 1; tmpg = g >> 1; tmpb = b >> 1; - megadrive_vdp_palette_lookup_shadow[offset] = (tmpb) | (tmpg << 5) | (tmpr << 10); + palette_set_color_rgb(space->machine(), offset + 0x800, pal5bit(tmpr), pal5bit(tmpg), pal5bit(tmpb)); // how is it calculated on c2? tmpr = tmpr | 0x10; tmpg = tmpg | 0x10; tmpb = tmpb | 0x10; - megadrive_vdp_palette_lookup_highlight[offset] = (tmpb) | (tmpg << 5) | (tmpr << 10); + palette_set_color_rgb(space->machine(), offset + 0x1000, pal5bit(tmpr), pal5bit(tmpg), pal5bit(tmpb)); } @@ -1261,27 +1271,74 @@ static const ym3438_interface ym3438_intf = static VIDEO_START(segac2_new) { VIDEO_START_CALL(megadriv); - - megadrive_vdp_palette_lookup = auto_alloc_array(machine, UINT16, 0x1000/2); - megadrive_vdp_palette_lookup_sprite = auto_alloc_array(machine, UINT16, 0x1000/2); - megadrive_vdp_palette_lookup_shadow = auto_alloc_array(machine, UINT16, 0x1000/2); - megadrive_vdp_palette_lookup_highlight = auto_alloc_array(machine, UINT16, 0x1000/2); } +// C2 doesn't use the internal VDP CRAM, instead it uses the digital output of the chip +// and applies it's own external colour circuity static SCREEN_UPDATE_RGB32(segac2_new) { + const pen_t *paldata = screen.machine().pens; segac2_state *state = screen.machine().driver_data(); if (!state->m_segac2_enable_display) { - bitmap.fill(get_black_pen(screen.machine())); + bitmap.fill(get_black_pen(screen.machine()), cliprect); return 0; } - SCREEN_UPDATE32_CALL(megadriv); + sega_genesis_vdp_device *vdp = state->m_vdp; + + /* Copy our screen buffer here */ + for (int y = cliprect.min_y; y <= cliprect.max_y; y++) + { + UINT32* desty = &bitmap.pix32(y, 0); + UINT16* srcy; + + srcy = vdp->m_render_line_raw; + + for (int x = cliprect.min_x; x <= cliprect.max_x; x++) + { + UINT16 src = srcy[x]; + switch (src & 0x1c0) + { + case 0x000: + desty[x] = paldata[(src&0x0f) | segac2_bg_pal_lookup[(src & 0x30)>>4] | 0x800]; + break; + case 0x040: + desty[x] = paldata[(src&0x0f) | segac2_bg_pal_lookup[(src & 0x30)>>4]]; + break; + case 0x080: + desty[x] = paldata[(src&0x0f) | segac2_sp_pal_lookup[(src & 0x30)>>4]]; + break; + case 0x0c0: + // bg pen + desty[x] = paldata[(src&0x0f) | segac2_bg_pal_lookup[(src & 0x30)>>4] | 0x1000]; + break; + case 0x100: + // shadow + desty[x] = paldata[(src&0x0f) | segac2_bg_pal_lookup[(src & 0x30)>>4] | 0x800]; + break; + case 0x140: + // normal + desty[x] = paldata[(src&0x0f) | segac2_bg_pal_lookup[(src & 0x30)>>4]]; + break; + case 0x180: + // sprite + desty[x] = paldata[(src&0x0f) | segac2_sp_pal_lookup[(src & 0x30)>>4]]; + break; + case 0x1c0: + // highlight + desty[x] = paldata[(src&0x0f) | segac2_bg_pal_lookup[(src & 0x30)>>4] | 0x1000]; + break; + } + } + } + return 0; } + + // the main interrupt on C2 comes from the vdp line used to drive the z80 interrupt on a regular genesis(!) void genesis_vdp_sndirqline_callback_segac2(running_machine &machine, bool state) { @@ -1335,7 +1392,7 @@ static MACHINE_CONFIG_START( segac, segac2_state ) MCFG_SCREEN_UPDATE_STATIC(segac2_new) MCFG_SCREEN_VBLANK_STATIC( megadriv ) - MCFG_PALETTE_LENGTH(2048) + MCFG_PALETTE_LENGTH(2048*3) MCFG_VIDEO_START(segac2_new) diff --git a/src/mame/drivers/segas18.c b/src/mame/drivers/segas18.c index fe12200cbf8..0585e64247a 100644 --- a/src/mame/drivers/segas18.c +++ b/src/mame/drivers/segas18.c @@ -62,12 +62,10 @@ #include "machine/segaic16.h" #include "machine/nvram.h" #include "includes/segas18.h" -#include "includes/genesis.h" #include "sound/2612intf.h" #include "sound/rf5c68.h" #include "includes/segaipt.h" - /************************************* * * Memory mapping tables @@ -105,7 +103,7 @@ void segas18_state::memory_mapper(sega_315_5195_mapper_device &mapper, UINT8 ind { case ROM_BOARD_171_SHADOW: break; // ??? case ROM_BOARD_171_5874: - case ROM_BOARD_171_5987: mapper.map_as_handler(0x00000, 0x00010, 0xfffff0, read16_delegate(FUNC(segas18_state::legacy_wrapper_r), this), write16_delegate(FUNC(segas18_state::legacy_wrapper), this)); break; + case ROM_BOARD_171_5987: mapper.map_as_handler(0x00000, 0x00010, 0xfffff0, read16_delegate(FUNC(segas18_state::genesis_vdp_r), this), write16_delegate(FUNC(segas18_state::genesis_vdp_w), this)); break; default: assert(false); } break; @@ -113,7 +111,7 @@ void segas18_state::memory_mapper(sega_315_5195_mapper_device &mapper, UINT8 ind case 1: switch (m_romboard) { - case ROM_BOARD_171_SHADOW: mapper.map_as_handler(0x00000, 0x00010, 0xfffff0, read16_delegate(FUNC(segas18_state::legacy_wrapper_r), this), write16_delegate(FUNC(segas18_state::legacy_wrapper), this)); break; + case ROM_BOARD_171_SHADOW: mapper.map_as_handler(0x00000, 0x00010, 0xfffff0, read16_delegate(FUNC(segas18_state::genesis_vdp_r), this), write16_delegate(FUNC(segas18_state::genesis_vdp_w), this)); break; case ROM_BOARD_171_5874: mapper.map_as_rom(0x00000, 0x80000, 0xf80000, "rom1base", 0x80000, write16_delegate()); break; case ROM_BOARD_171_5987: if (romsize <= 0x100000) mapper.map_as_rom(0x00000, 0x80000, 0xf80000, "rom1base", 0x80000, write16_delegate(FUNC(segas18_state::rom_5987_bank_w), this)); @@ -205,6 +203,9 @@ void segas18_state::machine_reset() { segaic16_tilemap_reset(machine(), 0); + megadriv_reset_vdp(machine()); + genvdp_use_cram = 1; + // if we are running with a real live 8751, we need to boost the interleave at startup if (m_mcu != NULL && m_mcu->type() == I8751) synchronize(TID_INITIAL_BOOST); @@ -567,6 +568,22 @@ WRITE8_MEMBER( segas18_state::mcu_data_w ) m_mcu->set_input_line(MCS51_INT1_LINE, HOLD_LINE); } +/************************************* + * + * VDP memory handlers + * + *************************************/ + +READ16_MEMBER( segas18_state::genesis_vdp_r ) +{ + return m_vdp->megadriv_vdp_r(space,offset,mem_mask); +} + +WRITE16_MEMBER( segas18_state::genesis_vdp_w ) +{ + m_vdp->megadriv_vdp_w(space,offset,data,mem_mask); +} + /************************************* @@ -1195,6 +1212,19 @@ GFXDECODE_END +// are any of the VDP interrupt lines hooked up to anything? +void genesis_vdp_sndirqline_callback_segas18(running_machine &machine, bool state) +{ +} + +void genesis_vdp_lv6irqline_callback_segas18(running_machine &machine, bool state) +{ +} + +void genesis_vdp_lv4irqline_callback_segas18(running_machine &machine, bool state) +{ +} + /************************************* * * Machine driver @@ -1216,6 +1246,17 @@ static MACHINE_CONFIG_START( system18, segas18_state ) MCFG_SEGA_315_5195_MAPPER_ADD("mapper", "maincpu", segas18_state, memory_mapper, mapper_sound_r, mapper_sound_w) + + MCFG_DEVICE_ADD("gen_vdp", SEGA_GEN_VDP, 0) + sega_genesis_vdp_device::set_genesis_vdp_sndirqline_callback(*device, genesis_vdp_sndirqline_callback_segas18); + sega_genesis_vdp_device::set_genesis_vdp_lv6irqline_callback(*device, genesis_vdp_lv6irqline_callback_segas18); + sega_genesis_vdp_device::set_genesis_vdp_lv4irqline_callback(*device, genesis_vdp_lv4irqline_callback_segas18); + sega_genesis_vdp_device::set_genesis_vdp_alt_timing(*device, 1); + sega_genesis_vdp_device::set_genesis_vdp_palwrite_base(*device, 0x2000); + + MCFG_TIMER_ADD_SCANLINE("scantimer", megadriv_scanline_timer_callback_alt_timing, "screen", 0, 1) + + // video hardware MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(57.23) // verified on pcb @@ -1224,7 +1265,7 @@ static MACHINE_CONFIG_START( system18, segas18_state ) MCFG_SCREEN_UPDATE_DRIVER(segas18_state, screen_update) MCFG_GFXDECODE(segas18) - MCFG_PALETTE_LENGTH(2048*3+2048) + MCFG_PALETTE_LENGTH(2048*3+2048 + 64*3) MCFG_SEGA16SP_ADD_16B("segaspr1") diff --git a/src/mame/includes/genesis.h b/src/mame/includes/genesis.h index 95bcf957fdf..d86162ca18b 100644 --- a/src/mame/includes/genesis.h +++ b/src/mame/includes/genesis.h @@ -1,13 +1 @@ -/* Todo, reorganise, cleanup etc.*/ - -/*----------- defined in video/genesis.c -----------*/ - -extern UINT16 genesis_bg_pal_lookup[4]; -extern UINT16 genesis_sp_pal_lookup[4]; -extern UINT8 genesis_vdp_regs[32]; - -void system18_vdp_start(running_machine &machine); -void system18_vdp_update(bitmap_ind16 &bitmap, const rectangle &cliprect); - -READ16_HANDLER ( genesis_vdp_r ); -WRITE16_HANDLER( genesis_vdp_w ); +/* Todo, delete! */ diff --git a/src/mame/includes/megadriv.h b/src/mame/includes/megadriv.h index aa911cb5c6d..49491673f78 100644 --- a/src/mame/includes/megadriv.h +++ b/src/mame/includes/megadriv.h @@ -452,8 +452,8 @@ extern WRITE16_HANDLER( jcart_ctrl_w ); extern READ16_HANDLER( jcart_ctrl_r ); /* machine/megavdp.c */ -extern UINT16 (*vdp_get_word_from_68k_mem)(running_machine &machine, UINT32 source); -extern UINT16 vdp_get_word_from_68k_mem_default(running_machine &machine, UINT32 source); +extern UINT16 (*vdp_get_word_from_68k_mem)(running_machine &machine, UINT32 source, address_space* space); +extern UINT16 vdp_get_word_from_68k_mem_default(running_machine &machine, UINT32 source, address_space* space); extern int megadriv_framerate; extern int megadrive_total_scanlines; extern int megadrive_vblank_flag; @@ -468,9 +468,7 @@ extern int genvdp_use_cram; extern int megadrive_region_export; extern int megadrive_region_pal; TIMER_DEVICE_CALLBACK( megadriv_scanline_timer_callback ); -TIMER_DEVICE_CALLBACK( megadriv_scanline_timer_callback_alt_timing ); /* machine/megadriv.c */ extern TIMER_DEVICE_CALLBACK( megadriv_scanline_timer_callback ); extern timer_device* megadriv_scanline_timer; -extern void megadriv_reset_vdp(running_machine &machine); diff --git a/src/mame/includes/segas18.h b/src/mame/includes/segas18.h index 969468ec3a6..b6cb77e2304 100644 --- a/src/mame/includes/segas18.h +++ b/src/mame/includes/segas18.h @@ -41,6 +41,7 @@ #include "machine/nvram.h" #include "machine/segaic16.h" #include "video/segaic16.h" +#include "machine/megavdp.h" // ======================> segas18_state @@ -55,6 +56,7 @@ public: m_maincpu(*this, "maincpu"), m_soundcpu(*this, "soundcpu"), m_mcu(*this, "mcu"), + m_vdp(*this, "gen_vdp"), m_nvram(*this, "nvram"), m_workram(*this, "workram"), m_romboard(ROM_BOARD_INVALID), @@ -93,6 +95,10 @@ public: DECLARE_WRITE8_MEMBER( soundbank_w ); DECLARE_WRITE8_MEMBER( mcu_data_w ); + DECLARE_READ16_MEMBER( genesis_vdp_r ); + DECLARE_WRITE16_MEMBER( genesis_vdp_w ); + + // custom I/O DECLARE_READ16_MEMBER( ddcrew_custom_io_r ); DECLARE_READ16_MEMBER( lghost_custom_io_r ); @@ -142,6 +148,7 @@ protected: required_device m_maincpu; required_device m_soundcpu; optional_device m_mcu; + required_device m_vdp; required_device m_nvram; // memory pointers diff --git a/src/mame/machine/megavdp.c b/src/mame/machine/megavdp.c index c3f6d9f4475..9c4c322ce96 100644 --- a/src/mame/machine/megavdp.c +++ b/src/mame/machine/megavdp.c @@ -30,16 +30,10 @@ int megadrive_total_scanlines; int megadrive_vblank_flag = 0; int genesis_scanline_counter = 0; -int segac2_bg_pal_lookup[4]; -int segac2_sp_pal_lookup[4]; // hacks for C2 int genvdp_use_cram = 0; // c2 uses it's own palette ram -UINT16* megadrive_vdp_palette_lookup; -UINT16* megadrive_vdp_palette_lookup_sprite; // for C2 -UINT16* megadrive_vdp_palette_lookup_shadow; -UINT16* megadrive_vdp_palette_lookup_highlight; int megadrive_region_export; int megadrive_region_pal; @@ -75,6 +69,7 @@ sega_genesis_vdp_device::sega_genesis_vdp_device(const machine_config &mconfig, m_genesis_vdp_lv6irqline_callback = genesis_vdp_lv6irqline_callback_default; m_genesis_vdp_lv4irqline_callback = genesis_vdp_lv4irqline_callback_default; m_use_alt_timing = 0; + m_palwrite_base = -1; } static TIMER_CALLBACK( megadriv_render_timer_callback ) @@ -134,6 +129,14 @@ void sega_genesis_vdp_device::set_genesis_vdp_alt_timing(device_t &device, int u dev.m_use_alt_timing = use_alt_timing; } +void sega_genesis_vdp_device::set_genesis_vdp_palwrite_base(device_t &device, int palwrite_base) +{ + sega_genesis_vdp_device &dev = downcast(device); + dev.m_palwrite_base = palwrite_base; +} + + + void sega_genesis_vdp_device::device_start() { @@ -178,6 +181,19 @@ void sega_genesis_vdp_device::device_start() m_highpri_renderline = auto_alloc_array(machine(), UINT8, 320); m_video_renderline = auto_alloc_array(machine(), UINT32, 320); + megadrive_vdp_palette_lookup = auto_alloc_array(machine(), UINT16, 0x40); + megadrive_vdp_palette_lookup_sprite = auto_alloc_array(machine(), UINT16, 0x40); + + megadrive_vdp_palette_lookup_shadow = auto_alloc_array(machine(), UINT16, 0x40); + megadrive_vdp_palette_lookup_highlight = auto_alloc_array(machine(), UINT16, 0x40); + + memset(megadrive_vdp_palette_lookup,0x00,0x40*2); + memset(megadrive_vdp_palette_lookup_sprite,0x00,0x40*2); + + memset(megadrive_vdp_palette_lookup_shadow,0x00,0x40*2); + memset(megadrive_vdp_palette_lookup_highlight,0x00,0x40*2); + + if (!m_use_alt_timing) { m_render_bitmap = auto_bitmap_ind16_alloc(machine(), machine().primary_screen->width(), machine().primary_screen->height()); @@ -187,11 +203,14 @@ void sega_genesis_vdp_device::device_start() m_render_line = auto_alloc_array(machine(), UINT16, machine().primary_screen->width()); } + m_render_line_raw = auto_alloc_array(machine(), UINT16, machine().primary_screen->width()); irq6_on_timer = machine().scheduler().timer_alloc(FUNC(irq6_on_timer_callback), (void*)this); irq4_on_timer = machine().scheduler().timer_alloc(FUNC(irq4_on_timer_callback), (void*)this); megadriv_render_timer = machine().scheduler().timer_alloc(FUNC(megadriv_render_timer_callback), (void*)this); + m_space68k = machine().device(":maincpu")->space(); + m_cpu68k = machine().device(":maincpu"); } void sega_genesis_vdp_device::device_reset() @@ -275,7 +294,12 @@ void sega_genesis_vdp_device::write_cram_value(running_machine &machine, int off r = ((data >> 1)&0x07); g = ((data >> 5)&0x07); b = ((data >> 9)&0x07); - palette_set_color_rgb(machine,offset,pal3bit(r),pal3bit(g),pal3bit(b)); + if (m_palwrite_base != -1) + { + palette_set_color_rgb(machine,offset + m_palwrite_base ,pal3bit(r),pal3bit(g),pal3bit(b)); + palette_set_color_rgb(machine,offset + m_palwrite_base + 0x40 ,pal3bit(r>>1),pal3bit(g>>1),pal3bit(b>>1)); + palette_set_color_rgb(machine,offset + m_palwrite_base + 0x80 ,pal3bit((r>>1)|0x4),pal3bit((g>>1)|0x4),pal3bit((b>>1)|0x4)); + } megadrive_vdp_palette_lookup[offset] = (b<<2) | (g<<7) | (r<<12); megadrive_vdp_palette_lookup_sprite[offset] = (b<<2) | (g<<7) | (r<<12); megadrive_vdp_palette_lookup_shadow[offset] = (b<<1) | (g<<6) | (r<<11); @@ -452,14 +476,13 @@ void sega_genesis_vdp_device::update_m_vdp_code_and_address(void) ((m_vdp_command_part2 & 0x0003) << 14); } -UINT16 (*vdp_get_word_from_68k_mem)(running_machine &machine, UINT32 source); +UINT16 (*vdp_get_word_from_68k_mem)(running_machine &machine, UINT32 source, address_space* space68k); -UINT16 vdp_get_word_from_68k_mem_default(running_machine &machine, UINT32 source) +UINT16 vdp_get_word_from_68k_mem_default(running_machine &machine, UINT32 source, address_space* space68k) { // should we limit the valid areas here? // how does this behave with the segacd etc? // note, the RV bit on 32x is important for this to work, because it causes a normal cart mapping - see tempo - address_space *space68k = machine.device("maincpu")->space(); //printf("vdp_get_word_from_68k_mem_default %08x\n", source); @@ -552,11 +575,11 @@ void sega_genesis_vdp_device::megadrive_do_insta_68k_to_vram_dma(running_machine if (length==0x00) length = 0xffff; /* This is a hack until real DMA timings are implemented */ - device_spin_until_time(machine.device(":maincpu"), attotime::from_nsec(length * 1000 / 3500)); + device_spin_until_time(m_cpu68k, attotime::from_nsec(length * 1000 / 3500)); for (count = 0;count<(length>>1);count++) { - vdp_vram_write(vdp_get_word_from_68k_mem(machine, source)); + vdp_vram_write(vdp_get_word_from_68k_mem(machine, source, m_space68k)); source+=2; if (source>0xffffff) source = 0xe00000; } @@ -582,7 +605,7 @@ void sega_genesis_vdp_device::megadrive_do_insta_68k_to_cram_dma(running_machine { //if (m_vdp_address>=0x80) return; // abandon - write_cram_value(machine, (m_vdp_address&0x7e)>>1, vdp_get_word_from_68k_mem(machine, source)); + write_cram_value(machine, (m_vdp_address&0x7e)>>1, vdp_get_word_from_68k_mem(machine, source, m_space68k)); source+=2; if (source>0xffffff) source = 0xfe0000; @@ -610,7 +633,7 @@ void sega_genesis_vdp_device::megadrive_do_insta_68k_to_vsram_dma(running_machin { if (m_vdp_address>=0x80) return; // abandon - m_vsram[(m_vdp_address&0x7e)>>1] = vdp_get_word_from_68k_mem(machine, source); + m_vsram[(m_vdp_address&0x7e)>>1] = vdp_get_word_from_68k_mem(machine, source, m_space68k); source+=2; if (source>0xffffff) source = 0xfe0000; @@ -2575,13 +2598,24 @@ void sega_genesis_vdp_device::genesis_render_videobuffer_to_screenbuffer(running } } + if (!(dat&0x20000)) + m_render_line_raw[x] = 0x100; + else + m_render_line_raw[x] = 0x000; + if (drawn==0) { if (dat&0x10000) - lineptr[x] = megadrive_vdp_palette_lookup_sprite[(dat&0x0f) | segac2_sp_pal_lookup[(dat&0x30)>>4]]; + { + lineptr[x] = megadrive_vdp_palette_lookup_sprite[(dat&0x3f)]; + m_render_line_raw[x] |= (dat & 0x3f) | 0x080; + } else - lineptr[x] = megadrive_vdp_palette_lookup[(dat&0x0f) | segac2_bg_pal_lookup[(dat&0x30)>>4]]; + { + lineptr[x] = megadrive_vdp_palette_lookup[(dat&0x3f)]; + m_render_line_raw[x] |= (dat & 0x3f) | 0x040; + } } @@ -2619,6 +2653,11 @@ void sega_genesis_vdp_device::genesis_render_videobuffer_to_screenbuffer(running } } + if (!(dat&0x20000)) + m_render_line_raw[x] = 0x100; + else + m_render_line_raw[x] = 0x000; + if (drawn==0) { @@ -2631,23 +2670,27 @@ void sega_genesis_vdp_device::genesis_render_videobuffer_to_screenbuffer(running case 0x10000: // (sprite) low priority, no shadow sprite, no highlight = shadow case 0x12000: // (sprite) low priority, shadow sprite, no highlight = shadow case 0x16000: // (sprite) normal pri, shadow sprite, no highlight = shadow? - lineptr[x] = megadrive_vdp_palette_lookup_shadow[(dat&0x0f) | segac2_bg_pal_lookup[(dat&0x30)>>4]]; + lineptr[x] = megadrive_vdp_palette_lookup_shadow[(dat&0x3f)]; + m_render_line_raw[x] |= (dat & 0x3f) | 0x000; break; case 0x4000: // normal pri, no shadow sprite, no highlight = normal; case 0x8000: // low pri, highlight sprite = normal; - lineptr[x] = megadrive_vdp_palette_lookup[(dat&0x0f) | segac2_bg_pal_lookup[(dat&0x30)>>4]]; + lineptr[x] = megadrive_vdp_palette_lookup[(dat&0x3f)]; + m_render_line_raw[x] |= (dat & 0x3f) | 0x040; break; case 0x14000: // (sprite) normal pri, no shadow sprite, no highlight = normal; case 0x18000: // (sprite) low pri, highlight sprite = normal; - lineptr[x] = megadrive_vdp_palette_lookup_sprite[(dat&0x0f) | segac2_sp_pal_lookup[(dat&0x30)>>4]]; + lineptr[x] = megadrive_vdp_palette_lookup_sprite[(dat&0x3f)]; + m_render_line_raw[x] |= (dat & 0x3f) | 0x080; break; case 0x0c000: // normal pri, highlight set = highlight? case 0x1c000: // (sprite) normal pri, highlight set = highlight? - lineptr[x] = megadrive_vdp_palette_lookup_highlight[(dat&0x0f) | segac2_bg_pal_lookup[(dat&0x30)>>4]]; + lineptr[x] = megadrive_vdp_palette_lookup_highlight[(dat&0x3f)]; + m_render_line_raw[x] |= (dat & 0x3f) | 0x0c0; break; case 0x0a000: // shadow set, highlight set - not possible @@ -2655,9 +2698,10 @@ void sega_genesis_vdp_device::genesis_render_videobuffer_to_screenbuffer(running case 0x1a000: // (sprite)shadow set, highlight set - not possible case 0x1e000: // (sprite)shadow set, highlight set, normal set, not possible default: - lineptr[x] = machine.rand()&0x3f; + lineptr[x] = m_render_line_raw[x] |= (machine.rand()&0x3f); break; } + } @@ -2701,28 +2745,6 @@ void sega_genesis_vdp_device::genesis_render_scanline(running_machine &machine) VIDEO_START(megadriv) { - megadrive_vdp_palette_lookup = auto_alloc_array(machine, UINT16, 0x40); - megadrive_vdp_palette_lookup_sprite = auto_alloc_array(machine, UINT16, 0x40); - - megadrive_vdp_palette_lookup_shadow = auto_alloc_array(machine, UINT16, 0x40); - megadrive_vdp_palette_lookup_highlight = auto_alloc_array(machine, UINT16, 0x40); - - memset(megadrive_vdp_palette_lookup,0x00,0x40*2); - memset(megadrive_vdp_palette_lookup_sprite,0x00,0x40*2); - - memset(megadrive_vdp_palette_lookup_shadow,0x00,0x40*2); - memset(megadrive_vdp_palette_lookup_highlight,0x00,0x40*2); - - /* no special lookups */ - segac2_bg_pal_lookup[0] = 0x00; - segac2_bg_pal_lookup[1] = 0x10; - segac2_bg_pal_lookup[2] = 0x20; - segac2_bg_pal_lookup[3] = 0x30; - - segac2_sp_pal_lookup[0] = 0x00; - segac2_sp_pal_lookup[1] = 0x10; - segac2_sp_pal_lookup[2] = 0x20; - segac2_sp_pal_lookup[3] = 0x30; } @@ -2879,16 +2901,16 @@ void sega_genesis_vdp_device::vdp_handle_eof(running_machine &machine) switch (MEGADRIVE_REG0C_RS0 | (MEGADRIVE_REG0C_RS1 << 1)) { /* note, add 240 mode + init new timings! */ - case 0:scr_width = 256;break;// configure_screen(0, 256-1, megadrive_visible_scanlines-1,(double)megadriv_framerate); break; - case 1:scr_width = 256;break;// configure_screen(0, 256-1, megadrive_visible_scanlines-1,(double)megadriv_framerate); mame_printf_debug("invalid screenmode!\n"); break; - case 2:scr_width = 320;break;// configure_screen(0, 320-1, megadrive_visible_scanlines-1,(double)megadriv_framerate); break; /* technically invalid, but used in rare cases */ - case 3:scr_width = 320;break;// configure_screen(0, 320-1, megadrive_visible_scanlines-1,(double)megadriv_framerate); break; + case 0:scr_width = 256;break; + case 1:scr_width = 256;break; + case 2:scr_width = 320;break; + case 3:scr_width = 320;break; } // mame_printf_debug("my mode %02x", m_vdp_regs[0x0c]); visarea.set(0, scr_width-1, 0, megadrive_visible_scanlines-1); - machine.primary_screen->configure(480, megadrive_total_scanlines, visarea, HZ_TO_ATTOSECONDS(megadriv_framerate)); + machine.primary_screen->configure(480, megadrive_total_scanlines, visarea, machine.primary_screen->frame_period().attoseconds); if(_32x_is_connected) diff --git a/src/mame/machine/megavdp.h b/src/mame/machine/megavdp.h index f816baa98b0..c842ffde9aa 100644 --- a/src/mame/machine/megavdp.h +++ b/src/mame/machine/megavdp.h @@ -146,6 +146,11 @@ typedef void (*genesis_vdp_sndirqline_callback_func)(running_machine &machine, b typedef void (*genesis_vdp_lv6irqline_callback_func)(running_machine &machine, bool state); typedef void (*genesis_vdp_lv4irqline_callback_func)(running_machine &machine, bool state); +TIMER_DEVICE_CALLBACK( megadriv_scanline_timer_callback_alt_timing ); +extern void megadriv_reset_vdp(running_machine &machine); +extern int genvdp_use_cram; + + class sega_genesis_vdp_device : public device_t { public: @@ -155,8 +160,11 @@ public: static void set_genesis_vdp_lv6irqline_callback(device_t &device, genesis_vdp_lv6irqline_callback_func callback); static void set_genesis_vdp_lv4irqline_callback(device_t &device, genesis_vdp_lv4irqline_callback_func callback); static void set_genesis_vdp_alt_timing(device_t &device, int use_alt_timing); + static void set_genesis_vdp_palwrite_base(device_t &device, int palwrite_base); int m_use_alt_timing; // use MAME scanline timer instead, render only one scanline to a single line buffer, to be rendered by a partial update call.. experimental + + int m_palwrite_base; // if we want to write to the actual MAME palette.. DECLARE_READ16_MEMBER( megadriv_vdp_r ); DECLARE_WRITE16_MEMBER( megadriv_vdp_w ); @@ -181,6 +189,7 @@ public: bitmap_ind16* m_render_bitmap; UINT16* m_render_line; + UINT16* m_render_line_raw; protected: virtual void device_start(); @@ -266,6 +275,13 @@ private: UINT8* m_sprite_renderline; UINT8* m_highpri_renderline; UINT32* m_video_renderline; + UINT16* megadrive_vdp_palette_lookup; + UINT16* megadrive_vdp_palette_lookup_sprite; // for C2 + UINT16* megadrive_vdp_palette_lookup_shadow; + UINT16* megadrive_vdp_palette_lookup_highlight; + + address_space *m_space68k; + legacy_cpu_device* m_cpu68k; }; diff --git a/src/mame/video/genesis.c b/src/mame/video/genesis.c index cae8130444e..08493637d79 100644 --- a/src/mame/video/genesis.c +++ b/src/mame/video/genesis.c @@ -1,1308 +1 @@ -/*********************************************************************************************** - - Old Genesis VDP emulation still used by System 18 - ------------------------------------------------- - - (originally used for Sega System C/C2 Driver, source version 0.54 - 02 Feb 2003) - -***********************************************************************************************/ - -#include "emu.h" -#include "sound/sn76496.h" -#include "includes/genesis.h" - - - -/****************************************************************************** - Macros -******************************************************************************/ - -#define BITMAP_WIDTH 320 -#define BITMAP_HEIGHT 240 - -#define VRAM_SIZE 0x10000 -#define VRAM_MASK (VRAM_SIZE - 1) -#define VSRAM_SIZE 0x80 -#define VSRAM_MASK (VSRAM_SIZE - 1) -#define CRAM_SIZE 0x40 -#define CRAM_MASK (CRAM_SIZE - 1) - -#define VDP_VRAM_BYTE(x) (vdp_vram[(x) & VRAM_MASK]) -#define VDP_VSRAM_BYTE(x) (vdp_vsram[(x) & VSRAM_MASK]) -#define VDP_VRAM_WORD(x) ((VDP_VRAM_BYTE(x) << 8) | VDP_VRAM_BYTE((x) + 1)) -#define VDP_VSRAM_WORD(x) ((VDP_VSRAM_BYTE(x) << 8) | VDP_VSRAM_BYTE((x) + 1)) - -#define EXTRACT_PIXEL(x,i) (((x) >> (((i) ^ NATIVE_ENDIAN_VALUE_LE_BE(1,7)) * 4)) & 0x0f) - - - -/****************************************************************************** - Function Prototypes -******************************************************************************/ - -static int vdp_data_r(running_machine &machine); -static void vdp_data_w(running_machine &machine, int data); -static int vdp_control_r(running_machine &machine); -static void vdp_control_w(address_space *space, int data); -static void vdp_register_w(running_machine &machine, int data, int vblank); -static void vdp_control_dma(address_space *space, int data); -static void vdp_dma_68k(address_space *space); -static void vdp_dma_fill(int); -static void vdp_dma_copy(void); - -static void drawline(UINT16 *bitmap, int line, int bgfill); -static void get_scroll_tiles(int line, int scrollnum, UINT32 scrollbase, UINT32 *tiles, int *offset); -static void get_window_tiles(int line, UINT32 scrollbase, UINT32 *tiles); -static void drawline_tiles(UINT32 *tiles, UINT16 *bmap, int pri, int offset, int lclip, int rclip); -static void drawline_sprite(int line, UINT16 *bmap, int priority, UINT8 *spritebase); - - - -/****************************************************************************** - Global variables -******************************************************************************/ - -/* EXTERNALLY ACCESSIBLE */ - UINT16 genesis_bg_pal_lookup[4]; /* lookup table for background tiles */ - UINT16 genesis_sp_pal_lookup[4]; /* lookup table for sprites */ - UINT8 genesis_vdp_regs[32]; /* VDP registers */ - -/* LOCAL */ -static screen_device *genesis_screen; - -static UINT8 * vdp_vram; /* VDP video RAM */ -static UINT8 * vdp_vsram; /* VDP vertical scroll RAM */ -static UINT8 display_enable; /* is the display enabled? */ -static int genesis_palette_base; /* offset to use when doing palette writes */ - -/* updates */ -static UINT16 * transparent_lookup; /* fast transparent mapping table */ - -/* vram bases */ -static UINT32 vdp_scrollabase; /* base address of scroll A tiles */ -static UINT32 vdp_scrollbbase; /* base address of scroll B tiles */ -static UINT32 vdp_windowbase; /* base address of window tiles */ -static UINT32 vdp_spritebase; /* base address of sprite data */ -static UINT32 vdp_hscrollbase; /* base address of H scroll values */ - -/* other vdp variables */ -static INT32 vdp_hscrollmask; /* mask for H scrolling */ -static UINT32 vdp_hscrollsize; /* size of active H scroll values */ -static UINT8 vdp_vscrollmode; /* current V scrolling mode */ - -static UINT8 vdp_cmdpart; /* partial command flag */ -static UINT8 vdp_code; /* command code value */ -static UINT32 vdp_address; /* current I/O address */ -static UINT8 vdp_dmafill; /* DMA filling flag */ -static UINT8 scrollheight; /* height of the scroll area in tiles */ -static UINT8 scrollwidth; /* width of the scroll area in tiles */ -static UINT8 bgcol; /* current background color */ -static UINT8 window_down; /* window Y direction */ -static UINT32 window_vpos; /* window Y position */ -static UINT8 window_right; /* window X direction */ -static UINT32 window_hpos; /* window X position */ -static UINT8 window_width; /* window width */ - - -/****************************************************************************** - Video Start / Stop Functions -******************************************************************************* - - Here we allocate memory used by the VDP and various other video related parts - of the System C/C2 hardware such as the Palette RAM. Here is what is needed - - 64kb of VRAM (multi-purpose, storing tiles, tilemaps, hscroll data, - spritelist etc.) - - 80bytes of VSRAM (used exclusively for storing Vertical Scroll values) - -******************************************************************************/ - - -static void start_genesis_vdp(screen_device &screen) -{ - static const UINT8 vdp_init[24] = - { - 0x04, 0x44, 0x30, 0x3C, 0x07, 0x6C, 0x00, 0x00, - 0x00, 0x00, 0xFF, 0x00, 0x01, 0x37, 0x00, 0x02, - 0x01, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x80, - }; - int i; - - genesis_screen = &screen; - - /* allocate memory for the VDP, the lookup table, and the buffer bitmap */ - vdp_vram = auto_alloc_array(screen.machine(), UINT8, VRAM_SIZE); - vdp_vsram = auto_alloc_array(screen.machine(), UINT8, VSRAM_SIZE); - transparent_lookup = auto_alloc_array(screen.machine(), UINT16, 0x1000); - - /* clear the VDP memory, prevents corrupt tile in Puyo Puyo 2 */ - memset(vdp_vram, 0, VRAM_SIZE); - memset(vdp_vsram, 0, VSRAM_SIZE); - - /* init transparency table */ - for (i = 0; i < 0x1000; i++) - { - int orig_color = i & 0x7ff; - int half_bright = i & 0x800; - - if (orig_color & 0x100) - transparent_lookup[i] = orig_color; - else if (half_bright) - transparent_lookup[i] = orig_color | 0x800; - else - transparent_lookup[i] = orig_color | 0x1000; - } - - /* reset the palettes */ - genesis_palette_base = 0; - genesis_bg_pal_lookup[0] = genesis_sp_pal_lookup[0] = 0x00; - genesis_bg_pal_lookup[1] = genesis_sp_pal_lookup[1] = 0x10; - genesis_bg_pal_lookup[2] = genesis_sp_pal_lookup[2] = 0x20; - genesis_bg_pal_lookup[3] = genesis_sp_pal_lookup[3] = 0x30; - - /* reset VDP */ - for (i = 0; i < 24; i++) - vdp_register_w(screen.machine(), 0x8000 | (i << 8) | vdp_init[i], 1); - vdp_cmdpart = 0; - vdp_code = 0; - vdp_address = 0; - - /* Save State Stuff */ - state_save_register_global_array(screen.machine(), genesis_vdp_regs); - state_save_register_global_pointer(screen.machine(), vdp_vram, 0x10000); - state_save_register_global_pointer(screen.machine(), vdp_vsram, 0x80); - state_save_register_global_array(screen.machine(), genesis_bg_pal_lookup); - state_save_register_global_array(screen.machine(), genesis_sp_pal_lookup); - state_save_register_global(screen.machine(), display_enable); - state_save_register_global(screen.machine(), vdp_scrollabase); - state_save_register_global(screen.machine(), vdp_scrollbbase); - state_save_register_global(screen.machine(), vdp_windowbase); - state_save_register_global(screen.machine(), vdp_spritebase); - state_save_register_global(screen.machine(), vdp_hscrollbase); - state_save_register_global(screen.machine(), vdp_hscrollmask); - state_save_register_global(screen.machine(), vdp_hscrollsize); - state_save_register_global(screen.machine(), vdp_vscrollmode); - state_save_register_global(screen.machine(), vdp_cmdpart); - state_save_register_global(screen.machine(), vdp_code); - state_save_register_global(screen.machine(), vdp_address); - state_save_register_global(screen.machine(), vdp_dmafill); - state_save_register_global(screen.machine(), scrollheight); - state_save_register_global(screen.machine(), scrollwidth); - state_save_register_global(screen.machine(), bgcol); - state_save_register_global(screen.machine(), window_down); - state_save_register_global(screen.machine(), window_vpos); -} - - -void system18_vdp_start(running_machine &machine) -{ - start_genesis_vdp(*machine.primary_screen); - - genesis_palette_base = 0x1800; - genesis_bg_pal_lookup[0] = genesis_sp_pal_lookup[0] = 0x1800; - genesis_bg_pal_lookup[1] = genesis_sp_pal_lookup[1] = 0x1810; - genesis_bg_pal_lookup[2] = genesis_sp_pal_lookup[2] = 0x1820; - genesis_bg_pal_lookup[3] = genesis_sp_pal_lookup[3] = 0x1830; -} - - - -/****************************************************************************** - Screen Refresh Functions -******************************************************************************* - - These are responsible for the core drawing. The update_display function - can be called under several circumstances to cache all the currently - displayed lines before a significant palette or scrolling change is - set to occur. The actual refresh routine marks the accumulated palette - entries and then converts the raw pens in the cache bitmap to their - final remapped values. - -******************************************************************************/ - -void system18_vdp_update( bitmap_ind16 &bitmap, const rectangle &cliprect ) -{ - int y; - - /* generate the final screen */ - for (y = cliprect.min_y; y <= cliprect.max_y; y++) - drawline(&bitmap.pix16(y), y, 0xffff); -} - -/****************************************************************************** - VDP Read & Write Handlers -******************************************************************************* - - The VDP is accessed via 8 & 16 bit reads / writes at the addresses 0xC00000 - - 0xC0001F. Different locations have different functions in the following - layout. (based on Information in Charles MacDonalds Document) - - 0xC00000 - DATA port (8 or 16 bit, Read or Write) - 0xC00002 - mirror of above - 0xC00004 - CTRL port (8 or 16 bit, Read or Write) - 0xC00006 - mirror of above - 0xC00008 - HV counter (8 or 16 bit Read Only) - 0xC0000A - mirror of above - 0xC0000C - mirror of above - 0xC0000E - mirror of above - 0xC00010 - SN76489 (8 bit Write Only) - 0xC00012 - mirror of above - 0xC00014 - mirror of above - 0xC00016 - mirror of above - - The SN76489 PSG Writes are intercepted before we get here and handled - directly. - -******************************************************************************/ - -READ16_HANDLER( genesis_vdp_r ) -{ - switch (offset) - { - case 0x00: /* Read Data */ - case 0x01: - return vdp_data_r(space->machine()); - - case 0x02: /* Status Register */ - case 0x03: - return vdp_control_r(space->machine()); - - case 0x04: /* HV counter */ - case 0x05: - case 0x06: - case 0x07: - { - int xpos = genesis_screen->hpos(); - int ypos = genesis_screen->vpos(); - - /* adjust for the weird counting rules */ - if (xpos > 0xe9) xpos -= (342 - 0x100); - if (ypos > 0xea) ypos -= (262 - 0x100); - - /* kludge for ichidant: it sets the H counter to 160, then */ - /* expects that a read from here will return 159 */ - if (ypos > 0) ypos -= 2; - return (ypos << 8) | xpos; - } - } - return 0; -} - - -WRITE16_HANDLER( genesis_vdp_w ) -{ - device_t *device; - switch (offset) - { - case 0x00: /* Write data */ - case 0x01: - if (mem_mask != 0xffff) - { - data &= mem_mask; - if (ACCESSING_BITS_8_15) - data |= data >> 8; - else - data |= data << 8; - } - vdp_data_w(space->machine(), data); - break; - - case 0x02: /* Control Write */ - case 0x03: - if (mem_mask != 0xffff) - { - data &= mem_mask; - if (ACCESSING_BITS_8_15) - data |= data >> 8; - else - data |= data << 8; - } - vdp_control_w(space, data); - break; - - case 0x08: /* SN76489 Write */ - case 0x09: - case 0x0a: - case 0x0b: - device = space->machine().device("snsnd"); - if (device != NULL && ACCESSING_BITS_0_7) - sn76496_w(device, 0, data & 0xff); - break; - } -} - - - -/****************************************************************************** - VDP DATA Reads / Writes (Accesses to 0xC00000 - 0xC00003) -******************************************************************************* - - The functions here are called by the read / write handlers for the VDP. - They deal with Data Reads and Writes to and from the VDP Chip. - - Read / write mode is set by Writes to VDP Control, Can't Read when in - write mode or vice versa. - -******************************************************************************/ - -/* Games needing Read to Work .. bloxeed (attract) .. puyo puyo .. probably more */ -static int vdp_data_r(running_machine &machine) -{ - int read = 0; - - /* kill 2nd write pending flag */ - vdp_cmdpart = 0; - - /* which memory is based on the code */ - switch (vdp_code & 0x0f) - { - case 0x00: /* VRAM read */ - read = VDP_VRAM_WORD(vdp_address & ~1); - break; - - case 0x04: /* VSRAM read */ - read = VDP_VSRAM_WORD(vdp_address & ~1); - break; - - default: /* Illegal read attempt */ - logerror("%s: VDP illegal read type %02x\n", machine.describe_context(), vdp_code); - read = 0x00; - break; - } - - /* advance the address */ - vdp_address += genesis_vdp_regs[15]; - return read; -} - - -static void vdp_data_w(running_machine &machine, int data) -{ - /* kill 2nd write pending flag */ - vdp_cmdpart = 0; - - /* handle the fill case */ - if (vdp_dmafill) - { - vdp_dma_fill(data); - vdp_dmafill = 0; - return; - } - - /* which memory is based on the code */ - switch (vdp_code & 0x0f) - { - case 0x01: /* VRAM write */ - - /* if the hscroll RAM is changing, force an update */ - if (vdp_address >= vdp_hscrollbase && - vdp_address < vdp_hscrollbase + vdp_hscrollsize) - machine.primary_screen->update_partial(machine.primary_screen->vpos()); - - /* write to VRAM */ - if (vdp_address & 1) - data = ((data & 0xff) << 8) | ((data >> 8) & 0xff); - VDP_VRAM_BYTE(vdp_address & ~1) = data >> 8; - VDP_VRAM_BYTE(vdp_address | 1) = data; - break; - - case 0x03: /* Palette write */ - { - int offset = (vdp_address/2) % CRAM_SIZE; - palette_set_color_rgb(machine, offset + genesis_palette_base, pal3bit(data >> 1), pal3bit(data >> 5), pal3bit(data >> 9)); - } - break; - - case 0x05: /* VSRAM write */ - - /* vscroll RAM is changing, force an update */ - machine.primary_screen->update_partial(machine.primary_screen->vpos()); - - /* write to VSRAM */ - if (vdp_address & 1) - data = ((data & 0xff) << 8) | ((data >> 8) & 0xff); - VDP_VSRAM_BYTE(vdp_address & ~1) = data >> 8; - VDP_VSRAM_BYTE(vdp_address | 1) = data; - break; - - default: /* Illegal write attempt */ - logerror("%s: VDP illegal write type %02x data %04x\n", machine.describe_context(), vdp_code, data); - break; - } - - /* advance the address */ - vdp_address += genesis_vdp_regs[15]; -} - - - -/****************************************************************************** - VDP CTRL Reads / Writes (Accesses to 0xC00004 - 0xC00007) -******************************************************************************* - - A Read from the Control Port will return the Status Register Value. - 16-bits are used to report the VDP status - | 0 | 0 | 1 | 1 | 0 | 1 | FIFE | FIFF | - | VIP | SOF | SCL | ODD | VBLK | HBLK | DMA | PAL | - - 0,1 = Set Values - FIFE = FIFO Empty - FIFF = FIFO Full - VIP = Vertical Interrupt Pending - SOF = Sprite Overflow (Not used in C2 afaik) - SCL = Sprite Collision (Not used in C2 afaik) - ODD = Odd Frame (Interlace Mode) (Not used in C2 afaik) - VBLK = In Vertical Blank - HBLK = In Horizontal Blank - DMA = DMA In Progress - PAL = Pal Mode Flag - - Control Writes are used for setting VDP Registers, setting up DMA Transfers - etc. - - A Write to the Control port can consist of 2 16-bit Words. - When the VDP _isn't_ expecting the 2nd part of a command the highest 2 bits - of the data written will determine what it is we want to do. - 10xxxxxx xxxxxxxx will cause a register to be set - anything else will trigger the 1st half of a 2 Part Mode Setting Command - If the VDP is already expecting the 2nd half of a command the data written - will be the 2nd half of the Mode setup. - -******************************************************************************/ - -static int vdp_control_r(running_machine &machine) -{ - int status = 0x3600; // wwally needs fifo empty set - - /* kill 2nd write pending flag */ - vdp_cmdpart = 0; - - /* set the VBLANK bit */ - if (machine.primary_screen->vblank()) - status |= 0x0008; - - /* set the HBLANK bit */ - if (machine.primary_screen->hblank()) - status |= 0x0004; - - return (status); -} - - -static void vdp_control_w(address_space *space, int data) -{ - /* case 1: we're not expecting the 2nd half of a command */ - if (!vdp_cmdpart) - { - /* if 10xxxxxx xxxxxxxx this is a register setting command */ - if ((data & 0xc000) == 0x8000) - vdp_register_w(space->machine(), data, space->machine().primary_screen->vblank()); - - /* otherwise this is the First part of a mode setting command */ - else - { - vdp_code = (vdp_code & 0x3c) | ((data >> 14) & 0x03); - vdp_address = (vdp_address & 0xc000) | (data & 0x3fff); - vdp_cmdpart = 1; - } - } - - /* case 2: this is the 2nd part of a mode setting command */ - else - { - vdp_code = (vdp_code & 0x03) | ((data >> 2) & 0x3c); - vdp_address = (vdp_address & 0x3fff) | ((data << 14) & 0xc000); - vdp_cmdpart = 0; - vdp_control_dma(space, data); - } -} - - -static void vdp_register_w(running_machine &machine, int data, int vblank) -{ - int scrwidth = 0; - static const UINT8 is_important[32] = { 0,0,1,1,1,1,0,1,0,0,0,1,0,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0 }; - - UINT8 regnum = (data & 0x1f00) >> 8; /* ---R RRRR ---- ---- */ - UINT8 regdat = (data & 0x00ff); /* ---- ---- DDDD DDDD */ - - genesis_vdp_regs[regnum] = regdat; - - /* these are mostly important writes; force an update if they written */ - if (is_important[regnum]) - machine.primary_screen->update_partial(machine.primary_screen->vpos()); - - /* For quite a few of the registers its a good idea to set a couple of variable based - upon the writes here */ - switch (regnum) - { - case 0x01: /* video modes */ - if (regdat & 8) - popmessage("Video height = 240!"); - break; - - case 0x02: /* Scroll A Name Table Base */ - vdp_scrollabase = (regdat & 0x38) << 10; - break; - - case 0x03: /* Window Name Table Base */ - vdp_windowbase = (regdat & 0x3e) << 10; - break; - - case 0x04: /* Scroll B Name Table Base */ - vdp_scrollbbase = (regdat & 0x07) << 13; - break; - - case 0x05: /* Sprite Table Base */ - vdp_spritebase = (regdat & 0x7e) << 9; - break; - - case 0x07: /* BG Colour */ - bgcol = regdat & 0x3f; - break; - - case 0x0b: /* Scroll Modes */ - { - static const UINT16 mask_table[4] = { 0x000, 0x007, 0xff8, 0xfff }; - vdp_vscrollmode = (regdat & 0x04) >> 2; - - vdp_hscrollmask = mask_table[regdat & 3]; - vdp_hscrollsize = 4 * ((vdp_hscrollmask < 224) ? (vdp_hscrollmask + 1) : 224); - break; - } - - case 0x0c: /* video modes */ - /* HDG: taken from mess/machine/genesis.c */ - switch (regdat&0x81) - { - case 0x00: // 32 cell - scrwidth=32; - window_width=32; - break; - case 0x01: // 40 cell corrupted - scrwidth=40; - window_width=64; - break; - case 0x80: // illegal! - scrwidth=40; - window_width=64; - break; - case 0x81: // 40 cell - scrwidth=40; - window_width=64; - break; - } - { - int height = genesis_screen->height(); - rectangle visarea = genesis_screen->visible_area(); - attoseconds_t refresh = genesis_screen->frame_period().attoseconds; - - /* this gets called from the init! */ - visarea.max_x = scrwidth*8-1; - genesis_screen->configure(scrwidth*8, height, visarea, refresh); - } - break; - - case 0x0d: /* HScroll Base */ - vdp_hscrollbase = (regdat & 0x3f) << 10; - break; - - case 0x10: /* Scroll Size */ - { - static const UINT8 size_table[4] = { 32, 64, 128, 128 }; - scrollwidth = size_table[regdat & 0x03]; - scrollheight = size_table[(regdat & 0x30) >> 4]; - break; - } - - case 0x11: /* Window H Position .. Doesn't Matter for any of the C2 Games */ - window_right = regdat & 0x80; - window_hpos = (regdat & 0x1f) << 4; - break; - - case 0x12: /* Window V Position */ - window_down = regdat & 0x80; - window_vpos = (regdat & 0x1f) << 3; - break; - } -} - - -static void vdp_control_dma(address_space *space, int data) -{ - if ((vdp_code & 0x20) && (genesis_vdp_regs[1] & 0x10)) - { - switch(genesis_vdp_regs[23] & 0xc0) - { - case 0x00: - case 0x40: /* 68k -> VRAM Tranfser */ - vdp_dma_68k(space); - break; - - case 0x80: /* VRAM fill, can't be done here, requires data write */ - vdp_dmafill = 1; - break; - - case 0xC0: /* VRAM copy */ - vdp_dma_copy(); - break; - } - } -} - - - -/****************************************************************************** - DMA handling -******************************************************************************* - - These are currently Pretty much directly from the C2 emu - -******************************************************************************/ - -static void vdp_dma_68k(address_space *space) -{ - int length = genesis_vdp_regs[19] | (genesis_vdp_regs[20] << 8); - int source = (genesis_vdp_regs[21] << 1) | (genesis_vdp_regs[22] << 9) | ((genesis_vdp_regs[23] & 0x7f) << 17); - int count; - - /* length of 0 means 64k likely */ - if (!length) - length = 0xffff; - - /* handle the DMA */ - for (count = 0; count < length; count++) - { - vdp_data_w(space->machine(), space->read_word(source)); - source += 2; - } -} - - -static void vdp_dma_copy(void) -{ - int length = genesis_vdp_regs[19] | (genesis_vdp_regs[20] << 8); - int source = genesis_vdp_regs[21] | (genesis_vdp_regs[22] << 8); - int count; - - /* length of 0 means 64k likely */ - if (!length) - length = 0xffff; - - /* handle the DMA */ - for (count = 0; count < length; count++) - { - VDP_VRAM_BYTE(vdp_address) = VDP_VRAM_BYTE(source++); - vdp_address += genesis_vdp_regs[15]; - } -} - - -static void vdp_dma_fill(int data) -{ - int length = genesis_vdp_regs[19] | (genesis_vdp_regs[20] << 8); - int count; - - /* length of 0 means 64k likely */ - if (!length) - length = 0xffff; - - /* handle the fill */ - VDP_VRAM_BYTE(vdp_address) = data; - data >>= 8; - for(count = 0; count < length; count++) - { - VDP_VRAM_BYTE(vdp_address ^ 1) = data; - vdp_address += genesis_vdp_regs[15]; - } -} - - - -/****************************************************************************** - Scroll calculations -******************************************************************************* - - These special routines handle the transparency effects in sprites. - -******************************************************************************/ - -/*** Useful Little Functions **************************************************/ - -/* Note: We Expect plane = 0 for Scroll A, plane = 2 for Scroll B */ -INLINE int vdp_gethscroll(int plane, int line) -{ - line &= vdp_hscrollmask; - return 0x400 - (VDP_VRAM_WORD(vdp_hscrollbase + (4 * line) + plane) & 0x3ff); -} - - -/* Note: We expect plane = 0 for Scroll A, plane = 2 for Scroll B - A Column is 8 Pixels Wide */ -static int vdp_getvscroll(int plane, int column) -{ - UINT32 vsramoffset; - - switch (vdp_vscrollmode) - { - case 0x00: /* Overall Scroll */ - return VDP_VSRAM_WORD(plane) & 0x7ff; - - case 0x01: /* Column Scroll */ - if (column == 40) column = 39; /* Fix Minor Innacuracy Only affects PotoPoto */ - vsramoffset = (4 * (column >> 1)) + plane; - return VDP_VSRAM_WORD(vsramoffset) & 0x7ff; - } - return 0; -} - - - -/****************************************************************************** - Drawing Functions -******************************************************************************* - - These are used by the Screen Refresh functions to do the actual rendering - of a screenline to the bitmap. - - Draw Planes in Order - Scroll B Low - Scroll A Low / Window Low - Sprites Low - Scroll B High - Scroll A High / Window High - Sprites High - - NOTE: Low Sprites _can_ overlap High sprites, however none of the C2 - games do this ever so its safe to draw them in this order. - -******************************************************************************/ - -static void drawline(UINT16 *bitmap, int line, int bgfill) -{ - int lowsprites, highsprites, link; - UINT32 scrolla_tiles[41], scrollb_tiles[41], window_tiles[41]; - int scrolla_offset, scrollb_offset; - UINT8 *lowlist[81], *highlist[81]; - int bgcolor = bgfill ? bgfill : genesis_bg_pal_lookup[0]; - int window_lclip, window_rclip; - int scrolla_lclip, scrolla_rclip; - int column, sprite; - - /* clear to the background color */ - for (column = 0; column < BITMAP_WIDTH; column++) - bitmap[column] = bgcolor; - - /* if display is disabled, stop */ - if (!(genesis_vdp_regs[1] & 0x40)) - return; - - /* Sprites need to be Drawn in Reverse order .. may as well sort them here */ - link = lowsprites = highsprites = 0; - for (sprite = 0; sprite < 80; sprite++) - { - UINT8 *spritebase = &VDP_VRAM_BYTE(vdp_spritebase + 8 * link); - - /* sort into high/low priorities */ - if (spritebase[4] & 0x0080) - highlist[++highsprites] = spritebase; - else - lowlist[++lowsprites] = spritebase; - - /* get the link; if 0, stop processing */ - link = spritebase[3] & 0x7F; - if (!link) - break; - } - - /* get tiles for the B scroll layer */ - get_scroll_tiles(line, 2, vdp_scrollbbase, scrollb_tiles, &scrollb_offset); - - /* get tiles for the A scroll layer */ - get_scroll_tiles(line, 0, vdp_scrollabase, scrolla_tiles, &scrolla_offset); - - /* get tiles for the window layer */ - get_window_tiles(line, vdp_windowbase, window_tiles); - - /* compute the windowing for this line */ - if ((window_down && line >= window_vpos) || (!window_down && line < window_vpos)) - window_lclip = 0, window_rclip = BITMAP_WIDTH - 1; - else if (window_right) - window_lclip = window_hpos, window_rclip = BITMAP_WIDTH - 1; - else - window_lclip = 0, window_rclip = window_hpos - 1; - - /* compute the clipping of the scroll A layer */ - if (window_lclip == 0) - { - scrolla_lclip = window_rclip + 1; - scrolla_rclip = BITMAP_WIDTH - 1; - } - else - { - scrolla_lclip = 0; - scrolla_rclip = window_lclip - 1; - } - - /* Scroll B Low */ - drawline_tiles(scrollb_tiles, bitmap, 0, scrollb_offset, 0, BITMAP_WIDTH - 1); - - /* Scroll A Low */ - drawline_tiles(scrolla_tiles, bitmap, 0, scrolla_offset, scrolla_lclip, scrolla_rclip); - - /* Window Low */ - drawline_tiles(window_tiles, bitmap, 0, 0, window_lclip, window_rclip); - - /* Sprites Low */ - for (sprite = lowsprites; sprite > 0; sprite--) - drawline_sprite(line, bitmap, 0, lowlist[sprite]); - - /* Scroll B High */ - drawline_tiles(scrollb_tiles, bitmap, 1, scrollb_offset, 0, BITMAP_WIDTH - 1); - - /* Scroll A High */ - drawline_tiles(scrolla_tiles, bitmap, 1, scrolla_offset, scrolla_lclip, scrolla_rclip); - - /* Window High */ - drawline_tiles(window_tiles, bitmap, 1, 0, window_lclip, window_rclip); - - /* Sprites High */ - for (sprite = highsprites; sprite > 0; sprite--) - drawline_sprite(line, bitmap, 1, highlist[sprite]); -} - - - -/****************************************************************************** - Background rendering -******************************************************************************* - - This code handles all the scroll calculations and rendering of the - background layers. - -******************************************************************************/ - -/* determine the tiles we will draw on a scrolling layer */ -static void get_scroll_tiles(int line, int scrollnum, UINT32 scrollbase, UINT32 *tiles, int *offset) -{ - int linehscroll = vdp_gethscroll(scrollnum, line); - int column; - - /* adjust for partial tiles and then pre-divide hscroll to get the tile offset */ - *offset = -(linehscroll % 8); - linehscroll /= 8; - - /* loop over columns */ - for (column = 0; column < 41; column++) - { - int columnvscroll = vdp_getvscroll(scrollnum, (column - (linehscroll & 1)) & 0x3f) + line; - - /* determine the base of the tilemap row */ - int temp = ((columnvscroll / 8) & (scrollheight - 1)) * scrollwidth; - int tilebase = scrollbase + 2 * temp; - - /* offset into the tilemap based on the column */ - temp = (linehscroll + column) & (scrollwidth - 1); - tilebase += 2 * temp; - - /* get the tile info */ - *tiles++ = ((columnvscroll % 8) << 16) | VDP_VRAM_WORD(tilebase); - } -} - - -/* determine the tiles we will draw on a non-scrolling window layer */ -static void get_window_tiles(int line, UINT32 scrollbase, UINT32 *tiles) -{ - int column; - - /* loop over columns */ - for (column = 0; column < 40; column++) - { - /* determine the base of the tilemap row */ - int temp = (line / 8) * window_width + column; - int tilebase = scrollbase + 2 * temp; - - /* get the tile info */ - *tiles++ = ((line % 8) << 16) | VDP_VRAM_WORD(tilebase); - } -} - - -/* draw a line of tiles */ -static void drawline_tiles(UINT32 *tiles, UINT16 *bmap, int pri, int offset, int lclip, int rclip) -{ - /* adjust for the 8-pixel slop */ - bmap += offset; - if (lclip > rclip) - return; - - /* loop over columns */ - for ( ; offset < BITMAP_WIDTH; offset += 8, bmap += 8) - { - UINT32 tile = *tiles++; - - /* if the tile is the correct priority, draw it */ - if (((tile >> 15) & 1) == pri && offset < BITMAP_WIDTH) - { - int colbase = genesis_bg_pal_lookup[(tile & 0x6000) >> 13]; - UINT32 *tp = (UINT32 *)&VDP_VRAM_BYTE((tile & 0x7ff) * 32); - UINT32 mytile; - int col; - - /* vertical flipping */ - if (!(tile & 0x1000)) - mytile = tp[tile >> 16]; - else - mytile = tp[(tile >> 16) ^ 7]; - - /* skip if all-transparent */ - if (!mytile) - continue; - - /* non-clipped */ - if (offset >= lclip && offset <= rclip - 7) - { - /* non-flipped */ - if (!(tile & 0x0800)) - { - col = EXTRACT_PIXEL(mytile, 0); if (col) bmap[0] = colbase + col; - col = EXTRACT_PIXEL(mytile, 1); if (col) bmap[1] = colbase + col; - col = EXTRACT_PIXEL(mytile, 2); if (col) bmap[2] = colbase + col; - col = EXTRACT_PIXEL(mytile, 3); if (col) bmap[3] = colbase + col; - col = EXTRACT_PIXEL(mytile, 4); if (col) bmap[4] = colbase + col; - col = EXTRACT_PIXEL(mytile, 5); if (col) bmap[5] = colbase + col; - col = EXTRACT_PIXEL(mytile, 6); if (col) bmap[6] = colbase + col; - col = EXTRACT_PIXEL(mytile, 7); if (col) bmap[7] = colbase + col; - } - - /* horizontal flip */ - else - { - col = EXTRACT_PIXEL(mytile, 7); if (col) bmap[0] = colbase + col; - col = EXTRACT_PIXEL(mytile, 6); if (col) bmap[1] = colbase + col; - col = EXTRACT_PIXEL(mytile, 5); if (col) bmap[2] = colbase + col; - col = EXTRACT_PIXEL(mytile, 4); if (col) bmap[3] = colbase + col; - col = EXTRACT_PIXEL(mytile, 3); if (col) bmap[4] = colbase + col; - col = EXTRACT_PIXEL(mytile, 2); if (col) bmap[5] = colbase + col; - col = EXTRACT_PIXEL(mytile, 1); if (col) bmap[6] = colbase + col; - col = EXTRACT_PIXEL(mytile, 0); if (col) bmap[7] = colbase + col; - } - } - - /* clipped */ - else if (offset >= lclip - 8 && offset <= rclip) - { - /* non-flipped */ - if (!(tile & 0x0800)) - { - col = EXTRACT_PIXEL(mytile, 0); if (col && (offset + 0) >= lclip && (offset + 0) <= rclip) bmap[0] = colbase + col; - col = EXTRACT_PIXEL(mytile, 1); if (col && (offset + 1) >= lclip && (offset + 1) <= rclip) bmap[1] = colbase + col; - col = EXTRACT_PIXEL(mytile, 2); if (col && (offset + 2) >= lclip && (offset + 2) <= rclip) bmap[2] = colbase + col; - col = EXTRACT_PIXEL(mytile, 3); if (col && (offset + 3) >= lclip && (offset + 3) <= rclip) bmap[3] = colbase + col; - col = EXTRACT_PIXEL(mytile, 4); if (col && (offset + 4) >= lclip && (offset + 4) <= rclip) bmap[4] = colbase + col; - col = EXTRACT_PIXEL(mytile, 5); if (col && (offset + 5) >= lclip && (offset + 5) <= rclip) bmap[5] = colbase + col; - col = EXTRACT_PIXEL(mytile, 6); if (col && (offset + 6) >= lclip && (offset + 6) <= rclip) bmap[6] = colbase + col; - col = EXTRACT_PIXEL(mytile, 7); if (col && (offset + 7) >= lclip && (offset + 7) <= rclip) bmap[7] = colbase + col; - } - - /* horizontal flip */ - else - { - col = EXTRACT_PIXEL(mytile, 7); if (col && (offset + 0) >= lclip && (offset + 0) <= rclip) bmap[0] = colbase + col; - col = EXTRACT_PIXEL(mytile, 6); if (col && (offset + 1) >= lclip && (offset + 1) <= rclip) bmap[1] = colbase + col; - col = EXTRACT_PIXEL(mytile, 5); if (col && (offset + 2) >= lclip && (offset + 2) <= rclip) bmap[2] = colbase + col; - col = EXTRACT_PIXEL(mytile, 4); if (col && (offset + 3) >= lclip && (offset + 3) <= rclip) bmap[3] = colbase + col; - col = EXTRACT_PIXEL(mytile, 3); if (col && (offset + 4) >= lclip && (offset + 4) <= rclip) bmap[4] = colbase + col; - col = EXTRACT_PIXEL(mytile, 2); if (col && (offset + 5) >= lclip && (offset + 5) <= rclip) bmap[5] = colbase + col; - col = EXTRACT_PIXEL(mytile, 1); if (col && (offset + 6) >= lclip && (offset + 6) <= rclip) bmap[6] = colbase + col; - col = EXTRACT_PIXEL(mytile, 0); if (col && (offset + 7) >= lclip && (offset + 7) <= rclip) bmap[7] = colbase + col; - } - } - } - } -} - - - -/****************************************************************************** - Sprite drawing -******************************************************************************* - - These special routines handle the transparency effects in sprites. - -******************************************************************************/ - -/* draw a non-horizontally-flipped section of a sprite */ -INLINE void draw8pixs(UINT16 *bmap, int sxpos, int patno, int priority, int colbase, int patline) -{ - UINT32 tile = *(UINT32 *)&VDP_VRAM_BYTE(patno * 32 + 4 * patline); - int col; - - /* skip if all-transparent */ - if (!tile) - return; - - /* non-transparent */ - if ((colbase & 0x30) != 0x30 || !(genesis_vdp_regs[12] & 0x08)) - { - if (sxpos>=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos=0 && sxpos> 2) + 1) * 8; - int spriteattr, patno, patflip, patline, colbase, x; - - /* skip if out of range */ - if (line < spriteypos || line >= spriteypos + spriteheight) - return; - if (spritexpos + spritewidth < 0 || spritexpos >= BITMAP_WIDTH) - return; - - /* extract the remaining data */ - spriteattr = (spritebase[4] << 8) | spritebase[5]; - patno = spriteattr & 0x07FF; - patflip = (spriteattr & 0x1800) >> 11; - patline = line - spriteypos; - - /* determine the color base */ - colbase = genesis_sp_pal_lookup[(spriteattr & 0x6000) >> 13]; - - /* adjust for the X position */ - spritewidth >>= 3; - spriteheight >>= 3; - - /* switch off the flip mode */ - switch (patflip) - { - case 0x00: /* No Flip */ - for (x = 0; x < spritewidth; x++) - { - if (spritexpos >= -7 && spritexpos < BITMAP_WIDTH) - draw8pixs(bmap, spritexpos, patno, priority, colbase, patline); - spritexpos += 8; - patno += spriteheight; - } - break; - - case 0x01: /* Horizontal Flip */ - patno += spriteheight * (spritewidth - 1); - for (x = 0; x < spritewidth; x++) - { - if (spritexpos >= -7 && spritexpos < BITMAP_WIDTH) - draw8pixs_hflip(bmap, spritexpos, patno, priority, colbase, patline); - spritexpos += 8; - patno -= spriteheight; - } - break; - - case 0x02: /* Vertical Flip */ - patline = 8 * spriteheight - patline - 1; - for (x = 0; x < spritewidth; x++) - { - if (spritexpos >= -7 && spritexpos < BITMAP_WIDTH) - draw8pixs(bmap, spritexpos, patno, priority, colbase, patline); - spritexpos += 8; - patno += spriteheight; - } - break; - - case 0x03: /* Both Flip */ - patno += spriteheight * (spritewidth - 1); - patline = 8 * spriteheight - patline - 1; - for (x = 0; x < spritewidth; x++) - { - if (spritexpos >= -7 && spritexpos < BITMAP_WIDTH) - draw8pixs_hflip(bmap, spritexpos, patno, priority, colbase, patline); - spritexpos += 8; - patno -= spriteheight; - } - break; - } -} - - - -/******************************************************************************/ -/* General Information (Mainly Genesis Related */ -/******************************************************************************/ -/* Genesis VDP Registers (from sega2.doc) - -Reg# : | Bit7 | Bit6 | Bit5 | Bit4 | Bit3 | Bit2 | Bit1 | Bit0 | General Function --------------------------------------------------------------------------------- -0x00 : | 0 | 0 | 0 | IE1 | 0 | 1 | M3 | 0 | Mode Set Register #1 -IE = Enabled H Interrupt (Lev 4), M3 = Enable HV Counter Read / Stopped -0x01 : | 0 | DISP | IE0 | M1 | M2 | 1 | 0 | 0 | Mode Set Register #2 -DISP = Display Enable, IE0 = Enabled V Interrupt (Lev 6), M1 = DMA Enabled, M2 = 30 Cell Mode -0x02 : | 0 | 0 | SA15 | SA14 | SA13 | 0 | 0 | 0 | Scroll A Base Address -SA13-15 = Bits 13-15 of the Scroll A Name Table Base Address in VRAM -0x03 : | 0 | 0 | WD15 | WD14 | WD13 | WD12 | WD11 | 0 | Window Base Address -WD11-15 = Bits 11-15 of the Window Name Table Base Address in VRAM -0x04 : | 0 | 0 | 0 | 0 | 0 | SB15 | SB14 | SB13 | Scroll B Base Address -SB13-15 = Bits 13-15 of the Scroll B Name Table Base Address in VRAM -0x05 : | 0 | AT15 | AT14 | AT13 | AT12 | AT11 | AT10 | AT9 | Sprite Table Base Address -AT9=15 = Bits 9-15 of the Sprite Name Table Base Address in VRAM -0x06 : | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | Unused -0x07 : | 0 | 0 | CPT1 | CPT0 | COL3 | COL2 | COL1 | COL0 | Background Colour Select -CPT0-1 = Palette Number, COL = Colour in Palette -0x08 : | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | Unused -0x09 : | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | Unused -0x0A : | BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2 | BIT1 | BIT0 | H-Interrupt Register -BIT0-7 = Controls Level 4 Interrupt Timing -0x0B : | 0 | 0 | 0 | 0 | IE2 | VSCR | HSCR | LSCR | Mode Set Register #3 -IE2 = Enable E Interrupt (Lev 2), VSCR = Vertical Scroll Mode, HSCR / LSCR = Horizontal Scroll Mode -0x0C : | RS0 | 0 | 0 | 0 | S/TE | LSM1 | LSM0 | RS1 | Mode Set Register #4 -RS0 / RS1 = Cell Mode, S/TE = Shadow/Hilight Enable, LSM0 / LSM1 = Interlace Mode Setting -0x0D : | 0 | 0 | HS15 | HS14 | HS13 | HS12 | HS11 | HS10 | HScroll Base Address -HS10-15 = Bits 10-15 of the HScroll Name Table Base Address in VRAM -0x0E : | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | Unused -0x0F : | INC7 | INC6 | INC5 | INC4 | INC3 | INC2 | INC1 | INC0 | Auto-Increment -INC0-7 = Auto Increment Value (after VRam Access) -0x10 : | 0 | 0 | VSZ1 | VSZ0 | 0 | 0 | HSZ1 | HSZ0 | Scroll Size -VSZ0-1 = Vertical Plane Size, HSZ0-1 = Horizontal Plane Size -0x11 : | RIGT | 0 | 0 | WHP5 | WHP4 | WHP3 | WHP2 | WHP1 | Window H Position -RIGT = Window Right Side of Base Point, WHP1-5 = Bits1-5 of Window H Point -0x12 : | DOWN | 0 | 0 | WVP4 | WVP3 | WVP2 | WVP1 | WVP0 | Window V Position -DOWN = Window Below Base Point, WVP0-4 = Bits0-4 of Window V Point -0x13 : | LG7 | LG6 | LG5 | LG4 | LG3 | LG2 | LG1 | LG0 | DMA Length Counter LOW -0x14 : | LG15 | LG14 | LG13 | LG12 | LG11 | LG10 | LG9 | LG8 | DMA Length Counter HIGH -LG0-15 = Bits 0-15 of DMA Length Counter -0x15 : | SA8 | SA7 | SA6 | SA5 | SA4 | SA3 | SA2 | SA1 | DMA Source Address LOW -0x16 : | SA16 | SA15 | SA14 | SA13 | SA12 | SA11 | SA10 | SA9 | DMA Source Address MID -0x17 : | DMD1 | DMD0 | SA22 | SA21 | SA20 | SA19 | SA18 | S17 | DMA Source Address HIGH -LG0-15 = Bits 1-22 of DMA Source Address -DMD0-1 = DMA Mode - -Memory Layouts ... - -Scroll Name Table -16-bits are used to Define a Tile in the Scroll Plane -| PRI | CP1 | CP0 | VF | HF | PT10 | PT9 | PT8 | -| PT7 | PT6 | PT5 | PT4 | PT3 | PT2 | PT1 | PT0 | -PRI = Priority, CP = Colour Palette, VF = VFlip, HF = HFlip, PT0-9 = Tile # in VRAM - -HScroll Data (in VRAM) -0x00 | -0x01 / H Scroll of Plane A (Used in Overall, Cell & Line Modes) -0x02 | -0x03 / H Scroll of Plane B (Used in Overall, Cell & Line Modes) -0x04 | -0x05 / H Scroll of Plane A (Used in Line Mode) -0x06 | -0x07 / H Scroll of Plane B (Used in Line Mode) -... -0x20 | -0x21 / H Scroll of Plane A (Used in Cell & Line Mode) -0x22 | -0x23 / H Scroll of Plane B (Used in Cell & Line Mode) -etc.. That kinda thing :) -Data is in Format .. -| x | x | x | x | x | x | HS9 | HS8 | -| HS7 | HS6 | HS5 | HS4 | HS3 | HS2 | HS1 | HS0 | -HS = HScroll Amount for Overall / Cell / Line depending on Mode. - -VScroll Data (in VSRAM) -0x00 | -0x01 / V Scroll of Plane A (Used in Overall & Cell Modes) -0x02 | -0x03 / V Scroll of Plane B (Used in Overall & Cell Modes) -0x04 | -0x05 / V Scroll of Plane A (Used in Cell Mode) -0x06 | -0x07 / V Scroll of Plane B (Used in Cell Modes) -etc.. -Data is in Format .. -| x | x | x | x | x | VS10 | VS9 | VS8 | -| VS7 | VS6 | VS5 | VS4 | VS3 | VS2 | VS1 | VS0 | -VS = HScroll Amount for Overall / Cell / Line depending on Mode. - -Sprite Attributes Table (in VRAM) -Each Sprite uses 64-bits of Information (8 bytes) -| x | x | x | x | x | x | YP9 | YP8 | -| YP7 | YP6 | YP5 | YP4 | YP3 | YP2 | YP1 | YP0 | -| x | x | x | x | HS1 | HS0 | VS1 | VS0 | -| x | LN6 | LN5 | LN4 | LN3 | LN2 | LN1 | LN0 | -| PRI | CP1 | CP0 | VF | HF | PT10 | PT9 | PT8 | -| PT7 | PT6 | PT5 | PT4 | PT3 | PT2 | PT1 | PT0 | -| x | x | x | x | x | x | XP9 | XP8 | -| XP7 | XP6 | XP5 | XP4 | XP3 | XP2 | XP1 | XP0 | -YP = Y Position of Sprite -HS = Horizontal Size (Blocks) -VS = Vertical Size (Blocks) -LN = Link Field -PRI = Priority -CP = Colour Palette -VF = VFlip -HF = HFlip -PT = Pattern Number -XP = X Position of Sprite - - - -*/ - +/* delete me */ diff --git a/src/mame/video/segas18.c b/src/mame/video/segas18.c index 82ecda0350b..098b05898ff 100644 --- a/src/mame/video/segas18.c +++ b/src/mame/video/segas18.c @@ -69,9 +69,6 @@ void segas18_state::video_start() // initialize the tile/text layers segaic16_tilemap_init(machine(), 0, SEGAIC16_TILEMAP_16B, 0x000, 0, 8); - // create the VDP - system18_vdp_start(machine()); - save_item(NAME(m_grayscale_enable)); save_item(NAME(m_vdp_enable)); save_item(NAME(m_vdp_mixing)); @@ -132,26 +129,42 @@ void segas18_state::set_vdp_mixing(UINT8 mixing) void segas18_state::draw_vdp(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int priority) { + bitmap_ind8 &priority_bitmap = screen.machine().priority_bitmap; for (int y = cliprect.min_y; y <= cliprect.max_y; y++) { - UINT16 *src = &m_temp_bitmap.pix(y); + // UINT16 *src = vdp->m_render_line; // can't use this because we're not in RGB32, which we'll need to be if there are palette effects + // UINT16 *src2 = vdp->m_render_line_raw; + UINT16 *dst = &bitmap.pix(y); UINT8 *pri = &priority_bitmap.pix(y); for (int x = cliprect.min_x; x <= cliprect.max_x; x++) { - UINT16 pix = src[x]; - if (pix != 0xffff) + if (m_vdp->m_render_line_raw[x] & 0x100) { - dst[x] = pix; - pri[x] |= priority; + int pix = m_vdp->m_render_line_raw[x] & 0x3f; + if (pix & 0xf) + { + switch (pix & 0xc0) + { + case 0x00: + dst[x] = pix + 0x2000; /* 0x2040 - would be shadow? */ + break; + case 0x40: + case 0x80: + dst[x] = pix + 0x2000; + break; + case 0xc0: + dst[x] = pix + 0x2000; /* 0x2080 - would be higlight? */ + break; + } + pri[x] |= priority; + } } } } } - - /************************************* * * Video update @@ -214,10 +227,6 @@ UINT32 segas18_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, return 0; } - // if the VDP is enabled, update our tmp_bitmap - if (m_vdp_enable) - system18_vdp_update(m_temp_bitmap, cliprect); - // reset priorities machine().priority_bitmap.fill(0, cliprect);