de-duplicate some code

This commit is contained in:
David Haywood 2013-09-26 01:29:17 +00:00
parent 55a6b403c9
commit b177d43676
3 changed files with 35 additions and 165 deletions

View File

@ -65,15 +65,15 @@ static ADDRESS_MAP_START( burglarx_map, AS_PROGRAM, 16, unico_state )
AM_RANGE(0x80001a, 0x80001b) AM_READ_PORT("DSW1")
AM_RANGE(0x80001c, 0x80001d) AM_READ_PORT("DSW2")
AM_RANGE(0x800030, 0x800031) AM_WRITENOP // ? 0
AM_RANGE(0x80010c, 0x800121) AM_WRITEONLY AM_SHARE("scroll") // Scroll
AM_RANGE(0x80010c, 0x800121) AM_READWRITE( unico_scroll_r, unico_scroll_w ) // Scroll
AM_RANGE(0x800188, 0x800189) AM_DEVREADWRITE8("oki", okim6295_device, read, write, 0x00ff) // Sound
AM_RANGE(0x80018a, 0x80018b) AM_DEVWRITE8("ymsnd", ym3812_device, write_port_w, 0xff00)
AM_RANGE(0x80018c, 0x80018d) AM_DEVREADWRITE8("ymsnd", ym3812_device, status_port_r, control_port_w, 0xff00)
AM_RANGE(0x80018e, 0x80018f) AM_WRITE(burglarx_sound_bank_w) //
AM_RANGE(0x8001e0, 0x8001e1) AM_WRITENOP // IRQ Ack
AM_RANGE(0x904000, 0x90ffff) AM_RAM_WRITE(unico_vram_w) AM_SHARE("vram") // Layers 1, 2, 0
AM_RANGE(0x904000, 0x90ffff) AM_READWRITE( unico_vram_r, unico_vram_w ) // Layers 1, 2, 0
AM_RANGE(0x920000, 0x923fff) AM_RAM // ? 0
AM_RANGE(0x930000, 0x9307ff) AM_RAM AM_SHARE("spriteram") // Sprites
AM_RANGE(0x930000, 0x9307ff) AM_READWRITE( unico_spriteram_r, unico_spriteram_w ) // Sprites
AM_RANGE(0x940000, 0x947fff) AM_RAM_WRITE(unico_palette_w) AM_SHARE("paletteram") // Palette
ADDRESS_MAP_END
@ -149,7 +149,7 @@ static ADDRESS_MAP_START( zeropnt_map, AS_PROGRAM, 16, unico_state )
AM_RANGE(0x800018, 0x800019) AM_READ_PORT("INPUTS")
AM_RANGE(0x80001a, 0x80001b) AM_READ_PORT("DSW1")
AM_RANGE(0x80001c, 0x80001d) AM_READ_PORT("DSW2")
AM_RANGE(0x80010c, 0x800121) AM_WRITEONLY AM_SHARE("scroll") // Scroll
AM_RANGE(0x80010c, 0x800121) AM_READWRITE( unico_scroll_r, unico_scroll_w ) // Scroll
AM_RANGE(0x800170, 0x800171) AM_READ(unico_guny_0_msb_r ) // Light Guns
AM_RANGE(0x800174, 0x800175) AM_READ(unico_gunx_0_msb_r ) //
AM_RANGE(0x800178, 0x800179) AM_READ(unico_guny_1_msb_r ) //
@ -159,9 +159,9 @@ static ADDRESS_MAP_START( zeropnt_map, AS_PROGRAM, 16, unico_state )
AM_RANGE(0x80018c, 0x80018d) AM_DEVREADWRITE8("ymsnd", ym3812_device, status_port_r, control_port_w, 0xff00)
AM_RANGE(0x80018e, 0x80018f) AM_WRITE(zeropnt_sound_bank_w ) //
AM_RANGE(0x8001e0, 0x8001e1) AM_WRITEONLY // ? IRQ Ack
AM_RANGE(0x904000, 0x90ffff) AM_RAM_WRITE(unico_vram_w) AM_SHARE("vram") // Layers 1, 2, 0
AM_RANGE(0x904000, 0x90ffff) AM_READWRITE( unico_vram_r, unico_vram_w ) // Layers 1, 2, 0
AM_RANGE(0x920000, 0x923fff) AM_RAM // ? 0
AM_RANGE(0x930000, 0x9307ff) AM_RAM AM_SHARE("spriteram") // Sprites
AM_RANGE(0x930000, 0x9307ff) AM_READWRITE( unico_spriteram_r, unico_spriteram_w ) // Sprites
AM_RANGE(0x940000, 0x947fff) AM_RAM_WRITE(unico_palette_w) AM_SHARE("paletteram") // Palette
ADDRESS_MAP_END
@ -222,7 +222,7 @@ static ADDRESS_MAP_START( zeropnt2_map, AS_PROGRAM, 32, unico_state )
AM_RANGE(0x800030, 0x800033) AM_DEVREADWRITE8("oki2", okim6295_device, read, write, 0x00ff0000 ) //
AM_RANGE(0x800034, 0x800037) AM_WRITE(zeropnt2_sound_bank_w ) //
AM_RANGE(0x800038, 0x80003b) AM_WRITE(zeropnt2_leds_w ) // ?
AM_RANGE(0x80010c, 0x800123) AM_WRITEONLY AM_SHARE("scroll32") // Scroll
AM_RANGE(0x80010c, 0x800123) AM_READWRITE16( unico_scroll_r, unico_scroll_w, 0xffffffff ) // Scroll
AM_RANGE(0x800140, 0x800143) AM_READ(zeropnt2_guny_0_msb_r ) // Light Guns
AM_RANGE(0x800144, 0x800147) AM_READ(zeropnt2_gunx_0_msb_r ) //
AM_RANGE(0x800148, 0x80014b) AM_READ(zeropnt2_guny_1_msb_r ) //
@ -232,9 +232,9 @@ static ADDRESS_MAP_START( zeropnt2_map, AS_PROGRAM, 32, unico_state )
AM_RANGE(0x80015c, 0x80015f) AM_READ_PORT("BUTTONS")
AM_RANGE(0x8001e0, 0x8001e3) AM_WRITENOP // ? IRQ Ack
AM_RANGE(0x8001f0, 0x8001f3) AM_WRITE(zeropnt2_eeprom_w) // EEPROM
AM_RANGE(0x904000, 0x90ffff) AM_RAM_WRITE(unico_vram32_w) AM_SHARE("vram32") // Layers 1, 2, 0
AM_RANGE(0x904000, 0x90ffff) AM_READWRITE16( unico_vram_r, unico_vram_w, 0xffffffff ) // Layers 1, 2, 0
AM_RANGE(0x920000, 0x923fff) AM_RAM // ? 0
AM_RANGE(0x930000, 0x9307ff) AM_RAM AM_SHARE("spriteram") // Sprites
AM_RANGE(0x930000, 0x9307ff) AM_READWRITE16( unico_spriteram_r, unico_spriteram_w, 0xffffffff ) // Sprites
AM_RANGE(0x940000, 0x947fff) AM_RAM_WRITE(unico_palette32_w) AM_SHARE("paletteram") // Palette
AM_RANGE(0xfe0000, 0xffffff) AM_RAM // RAM
ADDRESS_MAP_END
@ -673,12 +673,12 @@ static MACHINE_CONFIG_START( zeropnt2, unico_state )
MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
MCFG_SCREEN_SIZE(0x180, 0xe0)
MCFG_SCREEN_VISIBLE_AREA(0, 0x180-1, 0, 0xe0-1)
MCFG_SCREEN_UPDATE_DRIVER(unico_state, screen_update_zeropnt2)
MCFG_SCREEN_UPDATE_DRIVER(unico_state, screen_update_unico)
MCFG_GFXDECODE(unico)
MCFG_PALETTE_LENGTH(8192)
MCFG_VIDEO_START_OVERRIDE(unico_state,zeropnt2)
MCFG_VIDEO_START_OVERRIDE(unico_state,unico)
/* sound hardware */
MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")

View File

@ -6,23 +6,16 @@ class unico_state : public driver_device
public:
unico_state(const machine_config &mconfig, device_type type, const char *tag)
: driver_device(mconfig, type, tag),
m_vram(*this, "vram"),
m_scroll(*this, "scroll"),
m_vram32(*this, "vram32"),
m_scroll32(*this, "scroll32"),
m_spriteram(*this, "spriteram", 0),
m_maincpu(*this, "maincpu"),
m_oki(*this, "oki"),
m_eeprom(*this, "eeprom") { }
optional_shared_ptr<UINT16> m_vram;
optional_shared_ptr<UINT16> m_scroll;
optional_shared_ptr<UINT32> m_vram32;
optional_shared_ptr<UINT32> m_scroll32;
UINT16* m_vram;
UINT16* m_scroll;
tilemap_t *m_tilemap[3];
int m_sprites_scrolldx;
int m_sprites_scrolldy;
optional_shared_ptr<UINT16> m_spriteram;
UINT16* m_spriteram;
DECLARE_WRITE16_MEMBER(zeropnt_sound_bank_w);
DECLARE_READ16_MEMBER(unico_gunx_0_msb_r);
DECLARE_READ16_MEMBER(unico_guny_0_msb_r);
@ -36,20 +29,21 @@ public:
DECLARE_WRITE32_MEMBER(zeropnt2_leds_w);
DECLARE_WRITE16_MEMBER(unico_palette_w);
DECLARE_WRITE32_MEMBER(unico_palette32_w);
DECLARE_READ16_MEMBER(unico_vram_r);
DECLARE_WRITE16_MEMBER(unico_vram_w);
DECLARE_WRITE32_MEMBER(unico_vram32_w);
DECLARE_READ16_MEMBER(unico_scroll_r);
DECLARE_WRITE16_MEMBER(unico_scroll_w);
DECLARE_READ16_MEMBER(unico_spriteram_r);
DECLARE_WRITE16_MEMBER(unico_spriteram_w);
DECLARE_WRITE16_MEMBER(burglarx_sound_bank_w);
DECLARE_WRITE32_MEMBER(zeropnt2_eeprom_w);
TILE_GET_INFO_MEMBER(get_tile_info);
TILE_GET_INFO_MEMBER(get_tile_info32);
DECLARE_MACHINE_RESET(unico);
DECLARE_VIDEO_START(unico);
DECLARE_MACHINE_RESET(zeropt);
DECLARE_VIDEO_START(zeropnt2);
UINT32 screen_update_unico(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
UINT32 screen_update_zeropnt2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
void unico_draw_sprites(screen_device &screen, bitmap_ind16 &bitmap,const rectangle &cliprect);
void zeropnt2_draw_sprites(screen_device &screen, bitmap_ind16 &bitmap,const rectangle &cliprect);
required_device<cpu_device> m_maincpu;
optional_device<okim6295_device> m_oki;
optional_device<eeprom_serial_93cxx_device> m_eeprom;

View File

@ -96,13 +96,7 @@ TILE_GET_INFO_MEMBER(unico_state::get_tile_info)
SET_TILE_INFO_MEMBER(1, code, attr & 0x1f, TILE_FLIPYX( attr >> 5 ));
}
TILE_GET_INFO_MEMBER(unico_state::get_tile_info32)
{
UINT32 *vram = (UINT32 *)tilemap.user_data();
UINT16 code = vram[tile_index] >> 16;
UINT16 attr = vram[tile_index] & 0xff;
SET_TILE_INFO_MEMBER(1, code, attr & 0x1f, TILE_FLIPYX( attr >> 5 ));
}
READ16_MEMBER(unico_state::unico_vram_r) { return m_vram[offset]; }
WRITE16_MEMBER(unico_state::unico_vram_w)
{
@ -112,13 +106,11 @@ WRITE16_MEMBER(unico_state::unico_vram_w)
m_tilemap[tile]->mark_tile_dirty((offset & 0x1fff)/2);
}
WRITE32_MEMBER(unico_state::unico_vram32_w)
{
UINT32 *vram = m_vram32;
int tile = ((offset / 0x1000) + 1) % 3;
COMBINE_DATA(&vram[offset]);
m_tilemap[tile]->mark_tile_dirty((offset & 0xfff));
}
READ16_MEMBER(unico_state::unico_scroll_r) { return m_scroll[offset]; }
WRITE16_MEMBER(unico_state::unico_scroll_w) { COMBINE_DATA(&m_scroll[offset]); }
READ16_MEMBER(unico_state::unico_spriteram_r) { return m_spriteram[offset]; }
WRITE16_MEMBER(unico_state::unico_spriteram_w) { COMBINE_DATA(&m_spriteram[offset]); }
@ -133,6 +125,14 @@ WRITE32_MEMBER(unico_state::unico_vram32_w)
VIDEO_START_MEMBER(unico_state,unico)
{
m_vram = auto_alloc_array_clear(machine(), UINT16, 0xc000 / 2);
m_scroll = auto_alloc_array_clear(machine(), UINT16, 0x18 / 2);
m_spriteram = auto_alloc_array_clear(machine(), UINT16, 0x800 / 2);
save_pointer(NAME(m_vram), 0xc000/2);
save_pointer(NAME(m_scroll), 0x18/2);
save_pointer(NAME(m_spriteram), 0x800/2);
m_tilemap[0] = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(unico_state::get_tile_info),this),TILEMAP_SCAN_ROWS,
16,16, 0x40, 0x40);
@ -162,36 +162,6 @@ VIDEO_START_MEMBER(unico_state,unico)
m_tilemap[2]->set_transparent_pen(0x00);
}
VIDEO_START_MEMBER(unico_state,zeropnt2)
{
m_tilemap[0] = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(unico_state::get_tile_info32),this),TILEMAP_SCAN_ROWS,
16,16, 0x40, 0x40);
m_tilemap[1] = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(unico_state::get_tile_info32),this),TILEMAP_SCAN_ROWS,
16,16, 0x40, 0x40);
m_tilemap[2] = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(unico_state::get_tile_info32),this),TILEMAP_SCAN_ROWS,
16,16, 0x40, 0x40);
m_tilemap[0]->set_user_data(&m_vram32[0x8000/4]);
m_tilemap[1]->set_user_data(&m_vram32[0x0000/4]);
m_tilemap[2]->set_user_data(&m_vram32[0x4000/4]);
m_sprites_scrolldx = -0x3f;
m_sprites_scrolldy = -0x0e;
m_tilemap[0]->set_scrolldx(-0x32,0);
m_tilemap[1]->set_scrolldx(-0x30,0);
m_tilemap[2]->set_scrolldx(-0x2e,0);
m_tilemap[0]->set_scrolldy(-0x0f,0);
m_tilemap[1]->set_scrolldy(-0x0f,0);
m_tilemap[2]->set_scrolldy(-0x0f,0);
m_tilemap[0]->set_transparent_pen(0x00);
m_tilemap[1]->set_transparent_pen(0x00);
m_tilemap[2]->set_transparent_pen(0x00);
}
@ -223,7 +193,7 @@ void unico_state::unico_draw_sprites(screen_device &screen, bitmap_ind16 &bitmap
int offs;
/* Draw them backwards, for pdrawgfx */
for ( offs = (m_spriteram.bytes()-8)/2; offs >= 0 ; offs -= 8/2 )
for ( offs = (0x800-8)/2; offs >= 0 ; offs -= 8/2 )
{
int x, startx, endx, incx;
@ -271,61 +241,6 @@ void unico_state::unico_draw_sprites(screen_device &screen, bitmap_ind16 &bitmap
}
}
void unico_state::zeropnt2_draw_sprites(screen_device &screen, bitmap_ind16 &bitmap,const rectangle &cliprect)
{
UINT32 *spriteram32 = reinterpret_cast<UINT32 *>(m_spriteram.target());
int offs;
/* Draw them backwards, for pdrawgfx */
for ( offs = (m_spriteram.bytes()-8)/4; offs >= 0 ; offs -= 8/4 )
{
int x, startx, endx, incx;
int sx = spriteram32[ offs + 0 ] >> 16;
int sy = spriteram32[ offs + 0 ] & 0xffff;
int code = spriteram32[ offs + 1 ] >> 16;
int attr = spriteram32[ offs + 1 ] & 0xffff;
int flipx = attr & 0x020;
int flipy = attr & 0x040; // not sure
int dimx = ((attr >> 8) & 0xf) + 1;
int priority = ((attr >> 12) & 0x3);
int pri_mask;
switch( priority )
{
case 0: pri_mask = 0xfe; break; // below all
case 1: pri_mask = 0xf0; break; // above layer 0
case 2: pri_mask = 0xfc; break; // above layer 1
default:
case 3: pri_mask = 0x00; // above all
}
sx += m_sprites_scrolldx;
sy += m_sprites_scrolldy;
sx = (sx & 0x1ff) - (sx & 0x200);
sy = (sy & 0x1ff) - (sy & 0x200);
if (flipx) { startx = sx+(dimx-1)*16; endx = sx-16; incx = -16; }
else { startx = sx; endx = sx+dimx*16; incx = +16; }
for (x = startx ; x != endx ; x += incx)
{
pdrawgfx_transpen( bitmap, cliprect, machine().gfx[0],
code++,
attr & 0x1f,
flipx, flipy,
x, sy,
screen.priority(),
pri_mask,0x00 );
}
}
}
/***************************************************************************
@ -373,42 +288,3 @@ if ( machine().input().code_pressed(KEYCODE_Z) || machine().input().code_pressed
return 0;
}
UINT32 unico_state::screen_update_zeropnt2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
int layers_ctrl = -1;
m_tilemap[0]->set_scrollx(0, m_scroll32[0] >> 16);
m_tilemap[0]->set_scrolly(0, m_scroll32[0] & 0xffff);
m_tilemap[1]->set_scrollx(0, m_scroll32[2] & 0xffff);
m_tilemap[1]->set_scrolly(0, m_scroll32[5] >> 16);
m_tilemap[2]->set_scrollx(0, m_scroll32[2] >> 16);
m_tilemap[2]->set_scrolly(0, m_scroll32[1] >> 16);
#ifdef MAME_DEBUG
if ( machine().input().code_pressed(KEYCODE_Z) || machine().input().code_pressed(KEYCODE_X) )
{
int msk = 0;
if (machine().input().code_pressed(KEYCODE_Q)) msk |= 1;
if (machine().input().code_pressed(KEYCODE_W)) msk |= 2;
if (machine().input().code_pressed(KEYCODE_E)) msk |= 4;
if (machine().input().code_pressed(KEYCODE_A)) msk |= 8;
if (msk != 0) layers_ctrl &= msk;
}
#endif
/* The background color is the first of the last palette */
bitmap.fill(0x1f00, cliprect);
screen.priority().fill(0, cliprect);
if (layers_ctrl & 1) m_tilemap[0]->draw(screen, bitmap, cliprect, 0,1);
if (layers_ctrl & 2) m_tilemap[1]->draw(screen, bitmap, cliprect, 0,2);
if (layers_ctrl & 4) m_tilemap[2]->draw(screen, bitmap, cliprect, 0,4);
/* Sprites are drawn last, using pdrawgfx */
if (layers_ctrl & 8) zeropnt2_draw_sprites(screen,bitmap,cliprect);
return 0;
}