From 18c011160ae88efb18b0d865095059d0df577eaa Mon Sep 17 00:00:00 2001 From: angelosa Date: Thu, 19 May 2016 22:14:28 +0200 Subject: [PATCH] Sprites and initial workout in understanding how scroll works (nw) --- src/mame/drivers/metlfrzr.cpp | 76 +++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/src/mame/drivers/metlfrzr.cpp b/src/mame/drivers/metlfrzr.cpp index 863f5e3db19..583597bb45b 100644 --- a/src/mame/drivers/metlfrzr.cpp +++ b/src/mame/drivers/metlfrzr.cpp @@ -6,12 +6,13 @@ preliminary driver by Angelo Salese - HW seems the natural evolution of Dark Mist type HW. + HW seems the natural evolution of Dark Mist type. TODO: - T5182 hookup, controls sound and coin inputs. With current hookup it accepts coins but not fully, and sound isn't working at all ... - - Sprites, 0xfe00-0xffff? (And why game doesn't actually write at 0xff80-0xffff?) - - Foreground rowscroll / per-tile scroll; + - Still various unused bits. + - Nuke legacy video code and re-do it by using tilemap system. + - sprites are ahead of 1/2 frames; - Writes at 0xb800-0xbfff at attract mode gameplay demo transition? ****************************************/ @@ -30,6 +31,7 @@ public: m_decrypted_opcodes(*this, "decrypted_opcodes"), m_work_ram(*this, "wram"), m_vram(*this, "vram"), + m_video_regs(*this, "vregs"), m_palette(*this, "palette"), m_gfxdecode(*this, "gfxdecode") { } @@ -45,6 +47,7 @@ public: required_shared_ptr m_decrypted_opcodes; required_shared_ptr m_work_ram; required_shared_ptr m_vram; + required_shared_ptr m_video_regs; required_device m_palette; required_device m_gfxdecode; @@ -59,39 +62,80 @@ void metlfrzr_state::video_start() { } +/* + - video regs format: + [0x06] ---- --x- used during title screen transition, unknown purpose + [0x06] ---- ---x + [0x15] always 0? + [0x16] always 0? + [0x17] xxxx xxxx X scrolling base value + Notice that it's currently unknown how the game is really supposed to NOT enable scrolling during gameplay. + */ void metlfrzr_state::legacy_bg_draw(bitmap_ind16 &bitmap,const rectangle &cliprect) { gfx_element *gfx = m_gfxdecode->gfx(m_fg_tilebank); + const UINT16 vram_mask = m_vram.mask() >> 1; int count; - + int x_scroll_base; + int x_scroll_shift; + UINT16 x_scroll_value; + x_scroll_value = m_video_regs[0x17] + ((m_video_regs[0x06] & 1) << 8); + x_scroll_base = (x_scroll_value >> 3) * 32; + x_scroll_shift = (x_scroll_value & 7); + for (count=0;count<32*32;count++) { + int tile_base = count; int y = (count % 32); - int x = count / 32; + if(y > 7 || m_video_regs[0x06] & 3) // TODO: this condition breaks on level 5 halfway thru. + tile_base+= x_scroll_base; + else + x_scroll_shift = 0; + tile_base &= vram_mask; + int x = (count / 32); - UINT16 tile = m_vram[count*2+0] + ((m_vram[count*2+1] & 0xf0) << 4); - UINT8 color = m_vram[count*2+1] & 0xf; + + UINT16 tile = m_vram[tile_base*2+0] + ((m_vram[tile_base*2+1] & 0xf0) << 4); + UINT8 color = m_vram[tile_base*2+1] & 0xf; - gfx->transpen(bitmap,cliprect,tile,color,0,0,x*8,y*8,0xf); + gfx->transpen(bitmap,cliprect,tile,color,0,0,x*8-x_scroll_shift,y*8,0xf); } } +/* + sprite DMA: + 0xfe00-0xffff contains buffer for data to be copied. + Sprites are currently lagging (noticeable during scrolling) therefore there must be either an automatic or manual trigger. + Sprite seems to traverse from top to bottom priority-wise, other than that format is almost 1:1 with darkmist.cpp. + sprite format: + [0] tttt tttt tile number + [1] x--- ---- if 1 sprite is disabled + [1] -ttt ---- tile bank + [1] ---- cccc palette number + [2] yyyy yyyy Y offset + [3] xxxx xxxx X offset +*/ void metlfrzr_state::legacy_obj_draw(bitmap_ind16 &bitmap,const rectangle &cliprect) { - gfx_element *gfx = m_gfxdecode->gfx(3); + gfx_element *gfx_2 = m_gfxdecode->gfx(2); + gfx_element *gfx_3 = m_gfxdecode->gfx(3); int count; UINT8 *base_spriteram = m_work_ram + 0xe00; - - for(count=0;count<0x200;count+=4) + + for(count=0x200-4;count>-1;count-=4) { - UINT8 tile_bank = 0;//base_spriteram[count+1] & 3; + if(base_spriteram[count+1] & 0x80) + continue; + + gfx_element *cur_gfx = base_spriteram[count+1] & 0x40 ? gfx_3 : gfx_2; + UINT8 tile_bank = (base_spriteram[count+1] & 0x30) >> 4; UINT16 tile = base_spriteram[count] | (tile_bank << 8); UINT8 color = base_spriteram[count+1] & 0xf; int y = base_spriteram[count+2]; int x = base_spriteram[count+3]; - gfx->transpen(bitmap,cliprect,tile,color,0,0,x,y,0xf); + cur_gfx->transpen(bitmap,cliprect,tile,color,0,0,x,y,0xf); } } @@ -107,12 +151,12 @@ UINT32 metlfrzr_state::screen_update_metlfrzr(screen_device &screen, bitmap_ind1 WRITE8_MEMBER(metlfrzr_state::output_w) { // bit 7: flip screen - // bit 5: on title screen after coin is inserted + // bit 5: on title screen after coin is inserted. // bit 1-0: unknown purpose, both 1s too generally m_fg_tilebank = (data & 0x10) >> 4; membank("bank1")->set_entry((data & 0xc) >> 2); - popmessage("%02x",data & 3); + //popmessage("%02x",data & 3); if(data & 0x60) printf("%02x\n",data); } @@ -131,7 +175,7 @@ static ADDRESS_MAP_START( metlfrzr_map, AS_PROGRAM, 8, metlfrzr_state ) AM_RANGE(0xd602, 0xd602) AM_READ_PORT("START") AM_RANGE(0xd603, 0xd603) AM_READ_PORT("DSW1") AM_RANGE(0xd604, 0xd604) AM_READ_PORT("DSW2") - // d600-0d61f scroll area? + AM_RANGE(0xd600, 0xd61f) AM_RAM AM_SHARE("vregs") // TODO: write-only, debug AM_RANGE(0xd700, 0xd700) AM_WRITE(output_w) AM_RANGE(0xd710, 0xd710) AM_DEVWRITE("t5182", t5182_device, sound_irq_w)