From e72043f0d4ce15f9f33d6095b8643593b0b93b78 Mon Sep 17 00:00:00 2001 From: cam900 Date: Tue, 7 May 2019 09:53:35 +0900 Subject: [PATCH] blockout.cpp : Updates Simplify handlers, Use palette format for palette, Fix / Cleanup some drawing behavior, Fix namings, Fix spacings, Reduce unnecessary lines, Unnecessary pointers, Use shorter / correct type values --- src/mame/drivers/blockout.cpp | 23 ++++--- src/mame/includes/blockout.h | 21 +++--- src/mame/video/blockout.cpp | 118 ++++++++++++++-------------------- 3 files changed, 67 insertions(+), 95 deletions(-) diff --git a/src/mame/drivers/blockout.cpp b/src/mame/drivers/blockout.cpp index b35179f0f8f..a281259f69d 100644 --- a/src/mame/drivers/blockout.cpp +++ b/src/mame/drivers/blockout.cpp @@ -107,13 +107,13 @@ void blockout_state::main_map(address_map &map) map(0x100012, 0x100013).w(FUNC(blockout_state::blockout_irq5_ack_w)); map(0x100015, 0x100015).w(m_soundlatch, FUNC(generic_latch_8_device::write)); map(0x100016, 0x100017).nopw(); /* don't know, maybe reset sound CPU */ - map(0x180000, 0x1bffff).ram().w(FUNC(blockout_state::blockout_videoram_w)).share("videoram"); + map(0x180000, 0x1bffff).rw(FUNC(blockout_state::videoram_r), FUNC(blockout_state::videoram_w)).share("videoram"); map(0x1d4000, 0x1dffff).ram(); /* work RAM */ map(0x1f4000, 0x1fffff).ram(); /* work RAM */ map(0x200000, 0x207fff).ram().share("frontvideoram"); map(0x208000, 0x21ffff).ram(); /* ??? */ - map(0x280002, 0x280003).w(FUNC(blockout_state::blockout_frontcolor_w)); - map(0x280200, 0x2805ff).ram().w(FUNC(blockout_state::blockout_paletteram_w)).share("paletteram"); + map(0x280002, 0x280003).w(FUNC(blockout_state::frontcolor_w)); + map(0x280200, 0x2805ff).ram().w(m_palette, FUNC(palette_device::write16)).share("palette"); } void blockout_state::agress_map(address_map &map) @@ -128,13 +128,13 @@ void blockout_state::agress_map(address_map &map) map(0x100012, 0x100013).w(FUNC(blockout_state::blockout_irq5_ack_w)); map(0x100015, 0x100015).w(m_soundlatch, FUNC(generic_latch_8_device::write)); map(0x100016, 0x100017).nopw(); /* don't know, maybe reset sound CPU */ - map(0x180000, 0x1bffff).ram().w(FUNC(blockout_state::blockout_videoram_w)).share("videoram"); + map(0x180000, 0x1bffff).rw(FUNC(blockout_state::videoram_r), FUNC(blockout_state::videoram_w)).share("videoram"); map(0x1d4000, 0x1dffff).ram(); /* work RAM */ map(0x1f4000, 0x1fffff).ram(); /* work RAM */ map(0x200000, 0x207fff).ram().share("frontvideoram"); map(0x208000, 0x21ffff).ram(); /* ??? */ - map(0x280002, 0x280003).w(FUNC(blockout_state::blockout_frontcolor_w)); - map(0x280200, 0x2805ff).ram().w(FUNC(blockout_state::blockout_paletteram_w)).share("paletteram"); + map(0x280002, 0x280003).w(FUNC(blockout_state::frontcolor_w)); + map(0x280200, 0x2805ff).ram().w(m_palette, FUNC(palette_device::write16)).share("palette"); } void blockout_state::audio_map(address_map &map) @@ -297,10 +297,10 @@ TIMER_DEVICE_CALLBACK_MEMBER(blockout_state::blockout_scanline) { int scanline = param; - if(scanline == 250) // vblank-out irq + if (scanline == 250) // vblank-out irq m_maincpu->set_input_line(6, ASSERT_LINE); - if(scanline == 0) // vblank-in irq or directly tied to coin inputs (TODO: check) + if (scanline == 0) // vblank-in irq or directly tied to coin inputs (TODO: check) m_maincpu->set_input_line(5, ASSERT_LINE); } @@ -314,15 +314,14 @@ void blockout_state::blockout(machine_config &config) Z80(config, m_audiocpu, AUDIO_CLOCK); /* 3.579545 MHz */ m_audiocpu->set_addrmap(AS_PROGRAM, &blockout_state::audio_map); - /* video hardware */ SCREEN(config, m_screen, SCREEN_TYPE_RASTER); /* assume same as ddragon3 with adjusted visible display area */ m_screen->set_raw(XTAL(28'000'000) / 4, 448, 0, 320, 272, 10, 250); - m_screen->set_screen_update(FUNC(blockout_state::screen_update_blockout)); + m_screen->set_screen_update(FUNC(blockout_state::screen_update)); m_screen->set_palette(m_palette); - PALETTE(config, m_palette).set_entries(513); + PALETTE(config, m_palette).set_format(2, &blockout_state::blockout_xBGR_444, 513); /* sound hardware */ SPEAKER(config, "lspeaker").front_left(); @@ -451,7 +450,7 @@ void blockout_state::init_agress() * For now let's use D and just patch the TRACE exception that causes the bogus mirror check */ - uint16_t *rom = (uint16_t *)memregion("maincpu")->base(); + u16 *rom = (u16 *)memregion("maincpu")->base(); rom[0x82/2] = 0x2700; } diff --git a/src/mame/includes/blockout.h b/src/mame/includes/blockout.h index e842cde27a1..b29e177f1ae 100644 --- a/src/mame/includes/blockout.h +++ b/src/mame/includes/blockout.h @@ -17,9 +17,8 @@ class blockout_state : public driver_device public: blockout_state(const machine_config &mconfig, device_type type, const char *tag) : driver_device(mconfig, type, tag), - m_videoram(*this, "videoram"), + m_videoram(*this, "videoram", 16), m_frontvideoram(*this, "frontvideoram"), - m_paletteram(*this, "paletteram"), m_maincpu(*this, "maincpu"), m_audiocpu(*this, "audiocpu"), m_screen(*this, "screen"), @@ -27,13 +26,12 @@ public: m_soundlatch(*this, "soundlatch") { } /* memory pointers */ - required_shared_ptr m_videoram; - required_shared_ptr m_frontvideoram; - required_shared_ptr m_paletteram; + required_shared_ptr m_videoram; + required_shared_ptr m_frontvideoram; /* video-related */ bitmap_ind16 m_tmpbitmap; - uint16_t m_color; + u16 m_color; /* devices */ required_device m_maincpu; @@ -45,17 +43,16 @@ public: DECLARE_WRITE_LINE_MEMBER(irq_handler); DECLARE_WRITE16_MEMBER(blockout_irq6_ack_w); DECLARE_WRITE16_MEMBER(blockout_irq5_ack_w); - DECLARE_WRITE16_MEMBER(blockout_paletteram_w); - DECLARE_WRITE16_MEMBER(blockout_frontcolor_w); - DECLARE_WRITE16_MEMBER(blockout_videoram_w); + void frontcolor_w(offs_t offset, u16 data, u16 mem_mask = ~0); + u8 videoram_r(offs_t offset); + void videoram_w(offs_t offset, u8 data); void init_agress(); virtual void machine_start() override; virtual void machine_reset() override; virtual void video_start() override; - uint32_t screen_update_blockout(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); + u32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); TIMER_DEVICE_CALLBACK_MEMBER(blockout_scanline); - void setcolor( int color, int rgb ); - void update_pixels( int x, int y ); + static rgb_t blockout_xBGR_444(u32 raw); void blockout(machine_config &config); void agress(machine_config &config); void agress_map(address_map &map); diff --git a/src/mame/video/blockout.cpp b/src/mame/video/blockout.cpp index cc97fb44c26..1206a755bf5 100644 --- a/src/mame/video/blockout.cpp +++ b/src/mame/video/blockout.cpp @@ -10,50 +10,39 @@ #include "includes/blockout.h" -void blockout_state::setcolor( int color, int rgb ) +rgb_t blockout_state::blockout_xBGR_444(u32 raw) { - int bit0, bit1, bit2, bit3; - int r, g, b; - - /* red component */ - bit0 = (rgb >> 0) & 0x01; - bit1 = (rgb >> 1) & 0x01; - bit2 = (rgb >> 2) & 0x01; - bit3 = (rgb >> 3) & 0x01; - r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3; + u8 bit0 = (raw >> 0) & 0x01; + u8 bit1 = (raw >> 1) & 0x01; + u8 bit2 = (raw >> 2) & 0x01; + u8 bit3 = (raw >> 3) & 0x01; + const u8 r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3; /* green component */ - bit0 = (rgb >> 4) & 0x01; - bit1 = (rgb >> 5) & 0x01; - bit2 = (rgb >> 6) & 0x01; - bit3 = (rgb >> 7) & 0x01; - g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3; + bit0 = (raw >> 4) & 0x01; + bit1 = (raw >> 5) & 0x01; + bit2 = (raw >> 6) & 0x01; + bit3 = (raw >> 7) & 0x01; + const u8 g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3; /* blue component */ - bit0 = (rgb >> 8) & 0x01; - bit1 = (rgb >> 9) & 0x01; - bit2 = (rgb >> 10) & 0x01; - bit3 = (rgb >> 11) & 0x01; - b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3; + bit0 = (raw >> 8) & 0x01; + bit1 = (raw >> 9) & 0x01; + bit2 = (raw >> 10) & 0x01; + bit3 = (raw >> 11) & 0x01; + const u8 b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3; - m_palette->set_pen_color(color, rgb_t(r,g,b)); + return rgb_t(r, g, b); } -WRITE16_MEMBER(blockout_state::blockout_paletteram_w) -{ - COMBINE_DATA(&m_paletteram[offset]); - setcolor(offset, m_paletteram[offset]); -} - -WRITE16_MEMBER(blockout_state::blockout_frontcolor_w) +void blockout_state::frontcolor_w(offs_t offset, u16 data, u16 mem_mask) { COMBINE_DATA(&m_color); - setcolor(512, m_color); + m_palette->set_pen_color(512, blockout_xBGR_444(m_color)); } - /*************************************************************************** Start the video hardware emulation. @@ -62,65 +51,52 @@ WRITE16_MEMBER(blockout_state::blockout_frontcolor_w) void blockout_state::video_start() { /* Allocate temporary bitmaps */ - m_screen->register_screen_bitmap(m_tmpbitmap); + m_tmpbitmap.allocate(512, 256); + const rectangle clip(0, 511, 0, 255); + m_tmpbitmap.fill(0x100, clip); save_item(NAME(m_tmpbitmap)); } -void blockout_state::update_pixels( int x, int y ) +u8 blockout_state::videoram_r(offs_t offset) { - uint16_t front, back; - int color; - const rectangle &visarea = m_screen->visible_area(); + return m_videoram[offset]; +} - if (!visarea.contains(x, y)) - return; +void blockout_state::videoram_w(offs_t offset, u8 data) +{ + if (m_videoram[offset] != data) + { + m_videoram[offset] = data; + const u16 x = offset & 0x1ff; + const u16 y = (offset >> 9) & 0xff; + u16 color; - front = m_videoram[y * 256 + x / 2]; - back = m_videoram[0x10000 + y * 256 + x / 2]; + const u8 front = m_videoram[(y << 9) | x]; + const u8 back = m_videoram[0x20000 | (y << 9) | x]; - if (front >> 8) - color = front >> 8; - else - color = (back >> 8) + 256; + if (front) + color = front; + else + color = back | 0x100; - m_tmpbitmap.pix16(y, x) = color; - - if (front & 0xff) - color = front & 0xff; - else - color = (back & 0xff) + 256; - - m_tmpbitmap.pix16(y, x + 1) = color; + m_tmpbitmap.pix16(y, x) = color; + } } - -WRITE16_MEMBER(blockout_state::blockout_videoram_w) +u32 blockout_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) { - COMBINE_DATA(&m_videoram[offset]); - update_pixels((offset % 256) * 2, (offset / 256) % 256); -} - - - -uint32_t blockout_state::screen_update_blockout(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) -{ - int x, y; pen_t color = 512; copybitmap(bitmap, m_tmpbitmap, 0, 0, 0, 0, cliprect); - for (y = 0; y < 256; y++) + for (int y = cliprect.min_y; y <= cliprect.max_y; y++) { - for (x = 0; x < 320; x += 8) + for (int x = cliprect.min_x; x <= cliprect.max_x; x++) { - int d = m_frontvideoram[y * 64 + (x / 8)]; - int xi; - for(xi=0;xi<8;xi++) - { - if(d & 1 << (7-xi)) - bitmap.pix16(y, x + xi) = color; - } + const u16 d = m_frontvideoram[((y & 0xff) << 6) + ((x & 0x1ff) >> 3)]; + if (d & (1 << (7 - (x & 7)))) + bitmap.pix16(y, x) = color; } }