From 680854dd719d3936248caeedf082f4ab77c672fc Mon Sep 17 00:00:00 2001 From: cam900 Date: Mon, 20 May 2019 19:14:38 +0900 Subject: dreamwld.cpp : Updates Simplify handlers, Correct vram data type, Convert lineram into shared_ptr, Reduce unnecessary lines, Fix spacings, Namings, Use shorter / correct type values --- src/mame/drivers/dreamwld.cpp | 173 ++++++++++++++++++++---------------------- 1 file changed, 81 insertions(+), 92 deletions(-) diff --git a/src/mame/drivers/dreamwld.cpp b/src/mame/drivers/dreamwld.cpp index 8267c94898b..8c933089052 100644 --- a/src/mame/drivers/dreamwld.cpp +++ b/src/mame/drivers/dreamwld.cpp @@ -112,9 +112,10 @@ public: dreamwld_state(const machine_config &mconfig, device_type type, const char *tag) : driver_device(mconfig, type, tag) , m_spriteram(*this, "spriteram") - , m_vram(*this, "vram_%u", 0) + , m_vram(*this, "vram_%u", 0U, u8(32)) , m_vregs(*this, "vregs") , m_workram(*this, "workram") + , m_lineram(*this, "lineram", 32) , m_prot(*this, "prot") , m_spritelut(*this, "spritelut") , m_okibank(*this, "oki%ubank", 1) @@ -136,43 +137,43 @@ protected: private: /* memory pointers */ - required_shared_ptr m_spriteram; - required_shared_ptr_array m_vram; - required_shared_ptr m_vregs; - required_shared_ptr m_workram; + required_shared_ptr m_spriteram; + required_shared_ptr_array m_vram; + required_shared_ptr m_vregs; + required_shared_ptr m_workram; + required_shared_ptr m_lineram; optional_memory_region m_prot; required_memory_region m_spritelut; optional_memory_bank_array<2> m_okibank; required_ioport m_dsw; - std::unique_ptr m_lineram16; - - DECLARE_READ16_MEMBER(lineram16_r) { return m_lineram16[offset]; } - DECLARE_WRITE16_MEMBER(lineram16_w) { COMBINE_DATA(&m_lineram16[offset]); } + u16 lineram_r(offs_t offset) { return m_lineram[offset]; } + void lineram_w(offs_t offset, u16 data, u16 mem_mask = ~0) { COMBINE_DATA(&m_lineram[offset]); } /* video-related */ - tilemap_t *m_tilemap[2][2]; - int m_tilebank[2]; - int m_tilebankold[2]; - int m_old_linescroll[2]; + tilemap_t *m_tilemap[2][2]; + int m_tilebank[2]; + int m_tilebankold[2]; + int m_old_linescroll[2]; - std::unique_ptr m_spritebuf[2]; + std::unique_ptr m_spritebuf[2]; /* misc */ - int m_protindex; + int m_protindex; required_device m_maincpu; required_device m_gfxdecode; required_device m_palette; - template DECLARE_WRITE32_MEMBER(vram_w); - DECLARE_READ32_MEMBER(protdata_r); - template DECLARE_WRITE32_MEMBER(okibank_w); + template u16 vram_r(offs_t offset); + template void vram_w(offs_t offset, u16 data, u16 mem_mask = ~0); + u32 protdata_r(); + template void okibank_w(u8 data); template TILE_GET_INFO_MEMBER(get_tile_info); - uint32_t screen_update_dreamwld(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); - DECLARE_WRITE_LINE_MEMBER(screen_vblank_dreamwld); - void draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect ); + u32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); + DECLARE_WRITE_LINE_MEMBER(screen_vblank); + void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect); void baryon_map(address_map &map); void dreamwld_map(address_map &map); void oki1_map(address_map &map); @@ -180,36 +181,28 @@ private: }; - -void dreamwld_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect ) +void dreamwld_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect) { gfx_element *gfx = m_gfxdecode->gfx(0); - uint32_t *source = m_spritebuf[0].get(); - uint32_t *finish = m_spritebuf[0].get() + 0x1000 / 4; - uint16_t *redirect = (uint16_t *)m_spritelut->base(); - int xoffset = 4; + const u32 *source = m_spritebuf[0].get(); + const u32 *finish = m_spritebuf[0].get() + 0x1000 / 4; + const u16 *redirect = &m_spritelut->as_u16(); + const int xoffset = 4; while (source < finish) { - int xpos, ypos, tileno; - int xsize, ysize, xinc, yinc; - int xct, yct; - int xflip; - int yflip; - int colour; - - xpos = (source[0] & 0x000001ff) >> 0; - ypos = (source[0] & 0x01ff0000) >> 16; - xsize = (source[0] & 0x00000e00) >> 9; - ysize = (source[0] & 0x0e000000) >> 25; - - tileno = (source[1] & 0x0001ffff) >>0; - colour = (source[1] & 0x3f000000) >>24; - xflip = (source[1] & 0x40000000); - yflip = (source[1] & 0x80000000); - - xinc = 16; - yinc = 16; + int xpos = (source[0] & 0x000001ff) >> 0; + int ypos = (source[0] & 0x01ff0000) >> 16; + u8 xsize = (source[0] & 0x00000e00) >> 9; + u8 ysize = (source[0] & 0x0e000000) >> 25; + + u32 tileno = (source[1] & 0x0001ffff) >>0; + const u32 colour = (source[1] & 0x3f000000) >>24; + const bool xflip = (source[1] & 0x40000000); + const bool yflip = (source[1] & 0x80000000); + + int xinc = 16; + int yinc = 16; xpos += xoffset; xpos &= 0x1ff; @@ -230,10 +223,9 @@ void dreamwld_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &clipre xpos -=16; - - for (yct = 0; yct < ysize; yct++) + for (int yct = 0; yct < ysize; yct++) { - for (xct = 0; xct < xsize; xct++) + for (int xct = 0; xct < xsize; xct++) { gfx->transpen(bitmap,cliprect, redirect[tileno], colour, xflip, yflip, xpos + xct * xinc, ypos + yct * yinc, 0); gfx->transpen(bitmap,cliprect, redirect[tileno], colour, xflip, yflip, (xpos + xct * xinc) - 0x200, ypos + yct * yinc, 0); @@ -249,24 +241,27 @@ void dreamwld_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &clipre } template -WRITE32_MEMBER(dreamwld_state::vram_w) +u16 dreamwld_state::vram_r(offs_t offset) +{ + return m_vram[Layer][offset]; +} + +template +void dreamwld_state::vram_w(offs_t offset, u16 data, u16 mem_mask) { COMBINE_DATA(&m_vram[Layer][offset]); for (int size = 0; size < 2; size++) { - m_tilemap[Layer][size]->mark_tile_dirty(offset * 2); - m_tilemap[Layer][size]->mark_tile_dirty(offset * 2 + 1); + m_tilemap[Layer][size]->mark_tile_dirty(offset); } } template TILE_GET_INFO_MEMBER(dreamwld_state::get_tile_info) { - int tileno, colour; - tileno = (tile_index & 1) ? (m_vram[Layer][tile_index >> 1] & 0xffff) : ((m_vram[Layer][tile_index >> 1] >> 16) & 0xffff); - colour = tileno >> 13; - tileno &= 0x1fff; - SET_TILE_INFO_MEMBER(1, tileno + m_tilebank[Layer] * 0x2000, (Layer * 0x40) + colour, 0); + const u16 tileno = m_vram[Layer][tile_index]; + const u16 colour = tileno >> 13; + SET_TILE_INFO_MEMBER(1, (tileno & 0x1fff) | (m_tilebank[Layer] << 13), (Layer * 0x40) + colour, 0); } @@ -288,17 +283,15 @@ void dreamwld_state::video_start() } } - m_spritebuf[0] = std::make_unique(0x2000 / 4); - m_spritebuf[1] = std::make_unique(0x2000 / 4); - m_lineram16 = make_unique_clear(0x400 / 2); + m_spritebuf[0] = std::make_unique(0x2000 / 4); + m_spritebuf[1] = std::make_unique(0x2000 / 4); save_pointer(NAME(m_spritebuf[0]), 0x2000 / 4, 0); save_pointer(NAME(m_spritebuf[1]), 0x2000 / 4, 1); - save_pointer(NAME(m_lineram16), 0x400/2); } -WRITE_LINE_MEMBER(dreamwld_state::screen_vblank_dreamwld) +WRITE_LINE_MEMBER(dreamwld_state::screen_vblank) { // rising edge if (state) @@ -309,15 +302,13 @@ WRITE_LINE_MEMBER(dreamwld_state::screen_vblank_dreamwld) } -uint32_t dreamwld_state::screen_update_dreamwld(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) +u32 dreamwld_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) { tilemap_t *tmptilemap[2]; - uint32_t scrolly[2]{ m_vregs[(0x000 / 4)]+32, m_vregs[(0x008 / 4)]+32 }; - - uint32_t scrollx[2]{ m_vregs[(0x004 / 4)] + 0, m_vregs[(0x00c / 4)] + 2 }; - - uint32_t layer_ctrl[2]{ m_vregs[0x010 / 4], m_vregs[0x014 / 4] }; + const u32 scrolly[2]{ m_vregs[(0x000 / 4)] + 32, m_vregs[(0x008 / 4)] + 32 }; + const u32 scrollx[2]{ m_vregs[(0x004 / 4)] + 0, m_vregs[(0x00c / 4)] + 2 }; + const u32 layer_ctrl[2]{ m_vregs[0x010 / 4], m_vregs[0x014 / 4] }; for (int layer = 0; layer < 2; layer++) { @@ -331,28 +322,28 @@ uint32_t dreamwld_state::screen_update_dreamwld(screen_device &screen, bitmap_in } // Test mode only, Other size is enable? - int size = (layer_ctrl[layer] & 0x0400) >> 10; + const int size = (layer_ctrl[layer] & 0x0400) >> 10; tmptilemap[layer] = m_tilemap[layer][size]; - int row_mask = 0x3ff >> size; + const int row_mask = 0x3ff >> size; tmptilemap[layer]->set_scrolly(0, scrolly[layer]); if (layer_ctrl[layer] & 0x0300) { - int tile_rowscroll = (layer_ctrl[layer] & 0x0200) >> 7; + const int tile_rowscroll = (layer_ctrl[layer] & 0x0200) >> 7; if (m_old_linescroll[layer] != (layer_ctrl[layer] & 0x0300)) { for (int i = 0; i < 2; i++) { - m_tilemap[layer][i]->set_scroll_rows(((64*16) >> i)); + m_tilemap[layer][i]->set_scroll_rows(((64 * 16) >> i)); } m_old_linescroll[layer] = (layer_ctrl[layer] & 0x0300); } - uint16_t* linebase = &m_lineram16[(layer * 0x200) / 2]; + const u16* linebase = &m_lineram[(layer * 0x200) / 2]; for (int i = 0; i < 256; i++) /* 256 screen lines */ { /* per-line rowscroll */ - int x0 = linebase[((i+32)&0xff) >> tile_rowscroll]; + const int x0 = linebase[((i + 32) & 0xff) >> tile_rowscroll]; tmptilemap[layer]->set_scrollx( (i + scrolly[layer]) & row_mask, @@ -383,14 +374,15 @@ uint32_t dreamwld_state::screen_update_dreamwld(screen_device &screen, bitmap_in } - -READ32_MEMBER(dreamwld_state::protdata_r) +u32 dreamwld_state::protdata_r() { //static int count = 0; size_t protsize = m_prot->bytes(); - uint8_t dat = m_prot->base()[(m_protindex++) % protsize]; + const u8 dat = m_prot->base()[m_protindex]; + if (!machine().side_effects_disabled()) + m_protindex = (m_protindex + 1) % protsize; //printf("protection read %04x %02x\n", count, dat); //count++; @@ -413,12 +405,9 @@ void dreamwld_state::oki2_map(address_map &map) } template -WRITE32_MEMBER(dreamwld_state::okibank_w) +void dreamwld_state::okibank_w(u8 data) { - if (ACCESSING_BITS_0_7) - m_okibank[Chip]->set_entry(data&3); - else - logerror("OKI%x: unk bank write %x mem_mask %8x\n", Chip, data, mem_mask); + m_okibank[Chip]->set_entry(data & 3); } @@ -428,15 +417,15 @@ void dreamwld_state::baryon_map(address_map &map) map(0x400000, 0x401fff).ram().share("spriteram"); map(0x600000, 0x601fff).ram().w(m_palette, FUNC(palette_device::write32)).share("palette"); - map(0x800000, 0x801fff).ram().w(FUNC(dreamwld_state::vram_w<0>)).share("vram_0"); - map(0x802000, 0x803fff).ram().w(FUNC(dreamwld_state::vram_w<1>)).share("vram_1"); - map(0x804000, 0x8043ff).rw(FUNC(dreamwld_state::lineram16_r), FUNC(dreamwld_state::lineram16_w)); // linescroll + map(0x800000, 0x801fff).rw(FUNC(dreamwld_state::vram_r<0>), FUNC(dreamwld_state::vram_w<0>)).share("vram_0"); + map(0x802000, 0x803fff).rw(FUNC(dreamwld_state::vram_r<1>), FUNC(dreamwld_state::vram_w<1>)).share("vram_1"); + map(0x804000, 0x8043ff).rw(FUNC(dreamwld_state::lineram_r), FUNC(dreamwld_state::lineram_w)).share("lineram"); // linescroll map(0x804400, 0x805fff).ram().share("vregs"); map(0xc00000, 0xc00003).portr("INPUTS"); - map(0xc00004, 0xc00007).lr16("c00004", [this]() { return uint16_t(m_dsw->read()); }); + map(0xc00004, 0xc00007).lr16("c00004", [this]() { return u16(m_dsw->read()); }); - map(0xc0000c, 0xc0000f).w(FUNC(dreamwld_state::okibank_w<0>)); // sfx + map(0xc0000f, 0xc0000f).w(FUNC(dreamwld_state::okibank_w<0>)); // sfx map(0xc00018, 0xc00018).rw("oki1", FUNC(okim6295_device::read), FUNC(okim6295_device::write)); // sfx map(0xc00030, 0xc00033).r(FUNC(dreamwld_state::protdata_r)); // it reads protection data (irq code) from here and puts it at ffd000 @@ -448,7 +437,7 @@ void dreamwld_state::dreamwld_map(address_map &map) { baryon_map(map); - map(0xc0002c, 0xc0002f).w(FUNC(dreamwld_state::okibank_w<1>)); // sfx + map(0xc0002f, 0xc0002f).w(FUNC(dreamwld_state::okibank_w<1>)); // sfx map(0xc00028, 0xc00028).rw("oki2", FUNC(okim6295_device::read), FUNC(okim6295_device::write)); // sfx } @@ -723,13 +712,13 @@ void dreamwld_state::machine_start() { if (m_okibank[0].found()) { - m_okibank[0]->configure_entries(0, 4, memregion("oki1")->base()+0x30000, 0x10000); + m_okibank[0]->configure_entries(0, 4, memregion("oki1")->base() + 0x30000, 0x10000); m_okibank[0]->set_entry(0); } if (m_okibank[1].found()) { - m_okibank[1]->configure_entries(0, 4, memregion("oki2")->base()+0x30000, 0x10000); + m_okibank[1]->configure_entries(0, 4, memregion("oki2")->base() + 0x30000, 0x10000); m_okibank[1]->set_entry(0); } @@ -761,8 +750,8 @@ void dreamwld_state::baryon(machine_config &config) screen.set_vblank_time(ATTOSECONDS_IN_USEC(2500)); screen.set_size(512,256); screen.set_visarea(0, 308-1, 0, 224-1); - screen.set_screen_update(FUNC(dreamwld_state::screen_update_dreamwld)); - screen.screen_vblank().set(FUNC(dreamwld_state::screen_vblank_dreamwld)); + screen.set_screen_update(FUNC(dreamwld_state::screen_update)); + screen.screen_vblank().set(FUNC(dreamwld_state::screen_vblank)); screen.set_palette(m_palette); PALETTE(config, m_palette).set_format(palette_device::xRGB_555, 0x1000); -- cgit v1.2.3