From 696e7e8ef682096f08f34894c375a3373cf5f47b Mon Sep 17 00:00:00 2001 From: "Alex W. Jackson" Date: Sat, 15 Nov 2014 04:22:56 -0500 Subject: goldngam.c, popobear.c: fix unsafe casts pointed out by Aaron comments; the other driver with such comments, crystal.c, is a lost cause (nw) --- src/mame/drivers/goldngam.c | 12 +++++------ src/mame/drivers/popobear.c | 51 +++++++++++++++++---------------------------- 2 files changed, 24 insertions(+), 39 deletions(-) diff --git a/src/mame/drivers/goldngam.c b/src/mame/drivers/goldngam.c index c00a366c3cf..7e2a6a9d317 100644 --- a/src/mame/drivers/goldngam.c +++ b/src/mame/drivers/goldngam.c @@ -264,17 +264,15 @@ void goldngam_state::video_start() UINT32 goldngam_state::screen_update_goldngam(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) { - int x, y; - - // ERROR: This cast is NOT endian-safe without the use of BYTE/WORD/DWORD_XOR_* macros! - UINT8 *tmp = reinterpret_cast(m_videoram.target()); int index = 0; - for(y = 0; y < 512; ++y) + for(int y = 0; y < 512; ++y) { - for(x = 0; x < 384; ++x) + for(int x = 0; x < 384; x += 2) { - bitmap.pix16(y, x) = tmp[index ^ 1]; /* swapped bytes in 16 bit word */ + UINT16 word = m_videoram[index]; + bitmap.pix16(y, x) = word >> 8; + bitmap.pix16(y, x+1) = word & 0xff; ++index; } } diff --git a/src/mame/drivers/popobear.c b/src/mame/drivers/popobear.c index 380351115ee..e0801be11b4 100644 --- a/src/mame/drivers/popobear.c +++ b/src/mame/drivers/popobear.c @@ -89,6 +89,7 @@ public: : driver_device(mconfig, type, tag), m_maincpu(*this,"maincpu"), m_spr(*this, "spr"), + m_vram(*this, "vram"), m_vregs(*this, "vregs"), m_gfxdecode(*this, "gfxdecode"), m_palette(*this, "palette") @@ -98,24 +99,18 @@ public: tilemap_base[1] = 0xf4000; tilemap_base[2] = 0xf8000; tilemap_base[3] = 0xfc000; - - tilemap_size[0] = 0x04000; - tilemap_size[1] = 0x04000; - tilemap_size[2] = 0x04000; - tilemap_size[3] = 0x04000; } required_device m_maincpu; required_shared_ptr m_spr; + required_shared_ptr m_vram; required_shared_ptr m_vregs; optional_device m_gfxdecode; required_device m_palette; - UINT16* m_vram; - UINT16* m_vram_rearranged; + dynamic_array m_vram_rearranged; int tilemap_base[4]; - int tilemap_size[4]; DECLARE_READ8_MEMBER(popo_620000_r); DECLARE_WRITE8_MEMBER(popobear_irq_ack_w); @@ -124,7 +119,6 @@ public: TIMER_DEVICE_CALLBACK_MEMBER(popobear_irq); void draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect); - int m_gfx_index; tilemap_t *m_bg_tilemap[4]; TILE_GET_INFO_MEMBER(get_popobear_bg0_tile_info); TILE_GET_INFO_MEMBER(get_popobear_bg1_tile_info); @@ -149,7 +143,7 @@ public: COMBINE_DATA(&m_vram_rearranged[swapped_offset]); - m_gfxdecode->gfx(m_gfx_index)->mark_dirty((swapped_offset)/32); + m_gfxdecode->gfx(0)->mark_dirty((swapped_offset)/32); // unfortunately tilemaps and tilegfx share the same ram so we're always dirty if we write to RAM m_bg_tilemap[0]->mark_all_dirty(); @@ -158,7 +152,6 @@ public: m_bg_tilemap[3]->mark_all_dirty(); } - DECLARE_READ16_MEMBER(popo_vram_r) { return m_vram[offset]; } }; @@ -166,7 +159,7 @@ public: static const gfx_layout popobear_char_layout = { 8,8, - 0x4000, + RGN_FRAC(1,1), 8, { 0,1,2,3,4,5,6,7 }, { STEP8(0, 8) }, @@ -174,6 +167,9 @@ static const gfx_layout popobear_char_layout = 8*64 }; +GFXDECODE_START(popobear) + GFXDECODE_RAM( "vram", 0, popobear_char_layout, 0, 1 ) +GFXDECODE_END TILE_GET_INFO_MEMBER(popobear_state::get_popobear_bg0_tile_info) { @@ -212,19 +208,9 @@ TILE_GET_INFO_MEMBER(popobear_state::get_popobear_bg3_tile_info) void popobear_state::video_start() { - /* find first empty slot to decode gfx */ - for (m_gfx_index = 0; m_gfx_index < MAX_GFX_ELEMENTS; m_gfx_index++) - if (m_gfxdecode->gfx(m_gfx_index) == 0) - break; - - assert(m_gfx_index != MAX_GFX_ELEMENTS); - - m_vram = auto_alloc_array_clear(machine(), UINT16, 0x100000/2); - m_vram_rearranged = auto_alloc_array_clear(machine(), UINT16, 0x100000/2); + m_vram_rearranged.resize(0x100000 / 2); - - /* create the char set (gfx will then be updated dynamically from RAM) */ - m_gfxdecode->set_gfx(m_gfx_index, global_alloc(gfx_element(m_palette, popobear_char_layout, (UINT8 *)m_vram_rearranged, NATIVE_ENDIAN_VALUE_LE_BE(8,0), m_palette->entries() / 16, 0))); + m_gfxdecode->gfx(0)->set_source(reinterpret_cast(&m_vram_rearranged[0])); m_bg_tilemap[0] = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(popobear_state::get_popobear_bg0_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 64); m_bg_tilemap[1] = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(popobear_state::get_popobear_bg1_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 64); @@ -243,7 +229,6 @@ void popobear_state::video_start() void popobear_state::draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect) { - // ERROR: This cast is NOT endian-safe without the use of BYTE/WORD/DWORD_XOR_* macros! UINT8* vram = reinterpret_cast(m_spr.target()); int i; @@ -264,17 +249,19 @@ void popobear_state::draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect /* 0x*29 = 32 x 32 */ for(i = 0x800-8;i >= 0; i-=8) { - int y = vram[i+0x7f800+2]|(vram[i+0x7f800+3]<<8); - int x = vram[i+0x7f800+4]|(vram[i+0x7f800+5]<<8); - int spr_num = vram[i+0x7f800+6]|(vram[i+0x7f800+7]<<8); - int param = vram[i+0x7f800+0]|(vram[i+0x7f800+1]<<8); + UINT16 *sprdata = &m_spr[(0x7f800 + i) / 2]; + int param = sprdata[0]; int pri = (param & 0x0f00)>>8; // we do this because it's sprite<->sprite priority, if (pri!=drawpri) continue; + int y = sprdata[1]; + int x = sprdata[2]; + int spr_num = sprdata[3]; + int width = 8 << ((param & 0x30)>>4); int height = width; // sprites are always square? @@ -327,7 +314,7 @@ void popobear_state::draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect for(int xi=0;xi