From 7f92ee8016b4785a1e4408a7fb1d643e4a5d40d8 Mon Sep 17 00:00:00 2001 From: enikland2 Date: Sat, 30 Mar 2019 12:48:18 -0300 Subject: nes: Replace VDP bitmap access with screen().pixel() for lightgun emulation (#4665) --- src/devices/bus/nes_ctrl/ctrl.cpp | 1 - src/devices/bus/nes_ctrl/ctrl.h | 16 ---------------- src/devices/bus/nes_ctrl/zapper.cpp | 12 ++++++++++-- src/devices/bus/nes_ctrl/zapper.h | 1 + src/devices/video/ppu2c0x.cpp | 17 ----------------- src/devices/video/ppu2c0x.h | 1 - src/mame/drivers/nes.cpp | 4 ---- src/mame/includes/nes.h | 1 - src/mame/machine/nes.cpp | 13 ------------- src/mame/machine/playch10.cpp | 3 ++- src/mame/machine/vsnes.cpp | 3 ++- 11 files changed, 15 insertions(+), 57 deletions(-) diff --git a/src/devices/bus/nes_ctrl/ctrl.cpp b/src/devices/bus/nes_ctrl/ctrl.cpp index 2724e86dcaf..bacbd952c8a 100644 --- a/src/devices/bus/nes_ctrl/ctrl.cpp +++ b/src/devices/bus/nes_ctrl/ctrl.cpp @@ -125,7 +125,6 @@ nes_control_port_device::~nes_control_port_device() void nes_control_port_device::device_start() { m_device = dynamic_cast(get_card_device()); - m_brightpixel_cb.bind_relative_to(*owner()); } diff --git a/src/devices/bus/nes_ctrl/ctrl.h b/src/devices/bus/nes_ctrl/ctrl.h index 24a58b4f53c..27579717878 100644 --- a/src/devices/bus/nes_ctrl/ctrl.h +++ b/src/devices/bus/nes_ctrl/ctrl.h @@ -43,8 +43,6 @@ protected: nes_control_port_device *m_port; }; -#define NESCTRL_BRIGHTPIXEL_CB(name) bool name(int x, int y) - // ======================> nes_control_port_device @@ -65,25 +63,11 @@ public: nes_control_port_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); virtual ~nes_control_port_device(); - typedef device_delegate nesctrl_brightpixel_delegate; - - void set_brightpixel_callback(nesctrl_brightpixel_delegate callback) { m_brightpixel_cb = callback; } - template void set_brightpixel_callback(const char *devname, bool (FunctionClass::*callback)(int, int), const char *name) - { - set_brightpixel_callback(nesctrl_brightpixel_delegate(callback, name, devname, static_cast(nullptr))); - } - template void set_brightpixel_callback(bool (FunctionClass::*callback)(int, int), const char *name) - { - set_brightpixel_callback(nesctrl_brightpixel_delegate(callback, name, nullptr, static_cast(nullptr))); - } - uint8_t read_bit0(); uint8_t read_bit34(); uint8_t read_exp(offs_t offset); void write(uint8_t data); - nesctrl_brightpixel_delegate m_brightpixel_cb; - protected: // device-level overrides virtual void device_start() override; diff --git a/src/devices/bus/nes_ctrl/zapper.cpp b/src/devices/bus/nes_ctrl/zapper.cpp index 0996c893f0f..195ed891300 100644 --- a/src/devices/bus/nes_ctrl/zapper.cpp +++ b/src/devices/bus/nes_ctrl/zapper.cpp @@ -8,6 +8,7 @@ #include "emu.h" #include "zapper.h" +#include "screen.h" //************************************************************************** // DEVICE DEFINITIONS @@ -47,6 +48,7 @@ ioport_constructor nes_zapper_device::device_input_ports() const nes_zapper_device::nes_zapper_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, NES_ZAPPER, tag, owner, clock), + device_video_interface(mconfig, *this), device_nes_control_port_interface(mconfig, *this), m_lightx(*this, "ZAPPER_X"), m_lighty(*this, "ZAPPER_Y"), @@ -80,11 +82,17 @@ void nes_zapper_device::device_reset() uint8_t nes_zapper_device::read_bit34() { uint8_t ret = m_trigger->read(); - if (!m_port->m_brightpixel_cb.isnull() && - m_port->m_brightpixel_cb(m_lightx->read(), m_lighty->read())) + + // get the pixel at the gun position + rgb_t pix = screen().pixel(m_lightx->read(), m_lighty->read()); + + // check if the cursor is over a bright pixel + // FIXME: still a gross hack + if (pix.r() == 0xff && pix.b() == 0xff && pix.g() > 0x90) ret &= ~0x08; // sprite hit else ret |= 0x08; // no sprite hit + return ret; } diff --git a/src/devices/bus/nes_ctrl/zapper.h b/src/devices/bus/nes_ctrl/zapper.h index 5ae68fd0a6e..5c5c60c9386 100644 --- a/src/devices/bus/nes_ctrl/zapper.h +++ b/src/devices/bus/nes_ctrl/zapper.h @@ -21,6 +21,7 @@ // ======================> nes_zapper_device class nes_zapper_device : public device_t, + public device_video_interface, public device_nes_control_port_interface { public: diff --git a/src/devices/video/ppu2c0x.cpp b/src/devices/video/ppu2c0x.cpp index 8aa57660318..f82055140b7 100644 --- a/src/devices/video/ppu2c0x.cpp +++ b/src/devices/video/ppu2c0x.cpp @@ -1342,20 +1342,3 @@ uint32_t ppu2c0x_device::screen_update(screen_device &screen, bitmap_rgb32 &bitm render(bitmap, 0, 0, 0, 0); return 0; } - -/************************************* - * - * Utility functions - * - *************************************/ - -rgb_t ppu2c0x_device::get_pixel(int x, int y) -{ - if (x >= VISIBLE_SCREEN_WIDTH) - x = VISIBLE_SCREEN_WIDTH - 1; - - if (y >= VISIBLE_SCREEN_HEIGHT) - y = VISIBLE_SCREEN_HEIGHT - 1; - - return rgb_t(m_bitmap->pix32(y, x)); -} diff --git a/src/devices/video/ppu2c0x.h b/src/devices/video/ppu2c0x.h index 0dbb2dc690c..1f0eb086369 100644 --- a/src/devices/video/ppu2c0x.h +++ b/src/devices/video/ppu2c0x.h @@ -94,7 +94,6 @@ public: void spriteram_dma(address_space &space, const uint8_t page); void render(bitmap_rgb32 &bitmap, int flipx, int flipy, int sx, int sy); uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); - rgb_t get_pixel(int x, int y); int get_current_scanline() { return m_scanline; } void set_scanline_callback( scanline_delegate &&cb ) { m_scanline_callback_proc = std::move(cb); m_scanline_callback_proc.bind_relative_to(*owner()); } diff --git a/src/mame/drivers/nes.cpp b/src/mame/drivers/nes.cpp index 090834d40db..916ef864af9 100644 --- a/src/mame/drivers/nes.cpp +++ b/src/mame/drivers/nes.cpp @@ -76,9 +76,7 @@ void nes_state::nes(machine_config &config) // not sure how to adjust it when it's inside the CPU? NES_CONTROL_PORT(config, m_ctrl1, nes_control_port1_devices, "joypad"); - m_ctrl1->set_brightpixel_callback(FUNC(nes_state::bright_pixel)); NES_CONTROL_PORT(config, m_ctrl2, nes_control_port2_devices, "joypad"); - m_ctrl2->set_brightpixel_callback(FUNC(nes_state::bright_pixel)); NES_CART_SLOT(config, m_cartslot, NTSC_APU_CLOCK, nes_cart, nullptr); SOFTWARE_LIST(config, "cart_list").set_original("nes"); @@ -114,7 +112,6 @@ void nes_state::famicom(machine_config &config) NES_CONTROL_PORT(config.replace(), m_ctrl1, fc_control_port1_devices, "joypad"); NES_CONTROL_PORT(config.replace(), m_ctrl2, fc_control_port2_devices, "joypad"); NES_CONTROL_PORT(config, m_exp, fc_expansion_devices, nullptr); - m_exp->set_brightpixel_callback(FUNC(nes_state::bright_pixel)); SOFTWARE_LIST(config, "flop_list").set_original("famicom_flop"); SOFTWARE_LIST(config, "cass_list").set_original("famicom_cass"); @@ -145,7 +142,6 @@ void nes_state::famipalc(machine_config &config) NES_CONTROL_PORT(config.replace(), m_ctrl1, fc_control_port1_devices, "joypad"); NES_CONTROL_PORT(config.replace(), m_ctrl2, fc_control_port2_devices, "joypad"); NES_CONTROL_PORT(config, m_exp, fc_expansion_devices, nullptr); - m_exp->set_brightpixel_callback(FUNC(nes_state::bright_pixel)); SOFTWARE_LIST(config, "cass_list").set_original("famicom_cass"); } diff --git a/src/mame/includes/nes.h b/src/mame/includes/nes.h index 06dcf8f4366..17d0e8c6437 100644 --- a/src/mame/includes/nes.h +++ b/src/mame/includes/nes.h @@ -93,7 +93,6 @@ public: virtual void video_start() override; virtual void video_reset() override; uint32_t screen_update_nes(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); - NESCTRL_BRIGHTPIXEL_CB(bright_pixel); void init_famicom(); diff --git a/src/mame/machine/nes.cpp b/src/mame/machine/nes.cpp index 7b15384293e..d46c0ed286d 100644 --- a/src/mame/machine/nes.cpp +++ b/src/mame/machine/nes.cpp @@ -190,16 +190,3 @@ void nes_state::init_famicom() space.install_write_handler(0x4016, 0x4016, write8_delegate(FUNC(nes_state::fc_in0_w), this)); space.install_read_handler(0x4017, 0x4017, read8_delegate(FUNC(nes_state::fc_in1_r), this)); } - -NESCTRL_BRIGHTPIXEL_CB(nes_state::bright_pixel) -{ - // get the pixel at the gun position - rgb_t pix = m_ppu->get_pixel(x, y); - - // check if the cursor is over a bright pixel - // FIXME: still a gross hack - if (pix.r() == 0xff && pix.b() == 0xff && pix.g() > 0x90) - return true; - else - return false; -} diff --git a/src/mame/machine/playch10.cpp b/src/mame/machine/playch10.cpp index e9fde5b157c..2c2c29a9ec3 100644 --- a/src/mame/machine/playch10.cpp +++ b/src/mame/machine/playch10.cpp @@ -1,6 +1,7 @@ // license:BSD-3-Clause // copyright-holders:Ernesto Corvi,Brad Oliver #include "emu.h" +#include "screen.h" #include "includes/playch10.h" #include "machine/nvram.h" @@ -225,7 +226,7 @@ READ8_MEMBER(playch10_state::pc10_in1_r) ret |= 0x08; /* get the pixel at the gun position */ - rgb_t pix = m_ppu->get_pixel(x, y); + rgb_t pix = m_ppu->screen().pixel(x, y); /* look at the screen and see if the cursor is over a bright pixel */ // FIXME: still a gross hack diff --git a/src/mame/machine/vsnes.cpp b/src/mame/machine/vsnes.cpp index d5c1b3c4094..f7595acba77 100644 --- a/src/mame/machine/vsnes.cpp +++ b/src/mame/machine/vsnes.cpp @@ -10,6 +10,7 @@ Nintendo VS UniSystem and DualSystem - (c) 1984 Nintendo of America ***************************************************************************/ #include "emu.h" +#include "screen.h" #include "video/ppu2c0x.h" #include "includes/vsnes.h" @@ -375,7 +376,7 @@ WRITE8_MEMBER(vsnes_state::gun_in0_w) uint8_t realy = (int)y; /* get the pixel at the gun position */ - rgb_t col = m_ppu1->get_pixel(x, realy); + rgb_t col = m_ppu1->screen().pixel(x, realy); uint8_t bright = col.brightness(); // todo, calculate how bright it is with pix.r * 0.3 + pix.g * 0.59 + pix.b * 0.11 ? // the mame calc above is uint8_t brightness() const { return (r() * 222 + g() * 707 + b() * 71) / 1000; } (from lib/util/palette.h) -- cgit v1.2.3-70-g09d2