From 707ab9d5ab64b60b075360286a62bdd0b953ea2a Mon Sep 17 00:00:00 2001 From: cam900 Date: Tue, 13 Feb 2024 21:50:31 +0900 Subject: nec/pce.cpp, nec/pce_cd.cpp: Cleaned up code. (#11999) * nec/pce_cd.cpp: Use device_mixer_interface rather than using hard-coded speaker tags. * Merged nec/pce_m.cpp into nec/pce.cpp. * Reduced preprocessor macros, removed outdated comments, changed heaxadecimal digits to lowercase. --- src/mame/nec/pce.cpp | 106 +++++++++++++++++++++++++++++++++++++----------- src/mame/nec/pce.h | 15 ------- src/mame/nec/pce_cd.cpp | 11 ++--- src/mame/nec/pce_cd.h | 46 ++++++++++----------- src/mame/nec/pce_m.cpp | 69 ------------------------------- 5 files changed, 111 insertions(+), 136 deletions(-) delete mode 100644 src/mame/nec/pce_m.cpp diff --git a/src/mame/nec/pce.cpp b/src/mame/nec/pce.cpp index 37d12aefaa4..99ae503303a 100644 --- a/src/mame/nec/pce.cpp +++ b/src/mame/nec/pce.cpp @@ -69,27 +69,57 @@ Super System Card: #include "speaker.h" -// TODO: slotify this mess, also add alternate forms of input (multitap, mouse, pachinko controller etc.) -// hucard pachikun gives you option to select pachinko controller after pressing start, likely because it doesn't have a true header id -static INPUT_PORTS_START( pce ) +static constexpr XTAL MAIN_CLOCK = XTAL(21'477'272); + +static constexpr uint8_t TG_16_JOY_SIG = 0x00; +static constexpr uint8_t PCE_JOY_SIG = 0x40; +//static constexpr uint8_t NO_CD_SIG = 0x80; +//static constexpr uint8_t CD_SIG = 0x00; +/* these might be used to indicate something, but they always seem to return 1 */ +static constexpr uint8_t CONST_SIG = 0x30; - //PORT_START("JOY_P.1") - // pachinko controller paddle maps here (!?) with this arrangement - //PORT_BIT( 0xff, 0x00, IPT_PADDLE ) PORT_MINMAX(0,0x5f) PORT_SENSITIVITY(15) PORT_KEYDELTA(15) PORT_CENTERDELTA(0) PORT_CODE_DEC(KEYCODE_N) PORT_CODE_INC(KEYCODE_M) +// hucard pachikun gives you option to select pachinko controller after pressing start, likely because it doesn't have a true header id +static INPUT_PORTS_START( pce ) INPUT_PORTS_END +void pce_state::controller_w(u8 data) +{ + m_port_ctrl->sel_w(BIT(data, 0)); + m_port_ctrl->clr_w(BIT(data, 1)); +} + +u8 pce_state::controller_r() +{ + return (m_port_ctrl->port_r() & 0x0f) | m_io_port_options; +} + + +void pce_state::cd_intf_w(offs_t offset, u8 data) +{ + m_cd->update(); + + m_cd->intf_w(offset, data); + + m_cd->update(); +} + +u8 pce_state::cd_intf_r(offs_t offset) +{ + m_cd->update(); + return m_cd->intf_r(offset); +} void pce_state::pce_mem(address_map &map) { - map(0x100000, 0x10FFFF).ram().share("cd_ram"); - map(0x110000, 0x1EDFFF).noprw(); - map(0x1EE000, 0x1EE7FF).rw(m_cd, FUNC(pce_cd_device::bram_r), FUNC(pce_cd_device::bram_w)); - map(0x1EE800, 0x1EFFFF).noprw(); - map(0x1F0000, 0x1F1FFF).ram().mirror(0x6000); - map(0x1FE000, 0x1FE3FF).rw("huc6270", FUNC(huc6270_device::read), FUNC(huc6270_device::write)); - map(0x1FE400, 0x1FE7FF).rw(m_huc6260, FUNC(huc6260_device::read), FUNC(huc6260_device::write)); - map(0x1FF800, 0x1FFBFF).rw(FUNC(pce_state::cd_intf_r), FUNC(pce_state::cd_intf_w)); + map(0x100000, 0x10ffff).ram().share("cd_ram"); + map(0x110000, 0x1edfff).noprw(); + map(0x1ee000, 0x1ee7ff).rw(m_cd, FUNC(pce_cd_device::bram_r), FUNC(pce_cd_device::bram_w)); + map(0x1ee800, 0x1effff).noprw(); + map(0x1f0000, 0x1f1fff).ram().mirror(0x6000); + map(0x1fe000, 0x1fe3ff).rw("huc6270", FUNC(huc6270_device::read), FUNC(huc6270_device::write)); + map(0x1fe400, 0x1fe7ff).rw(m_huc6260, FUNC(huc6260_device::read), FUNC(huc6260_device::write)); + map(0x1ff800, 0x1ffbff).rw(FUNC(pce_state::cd_intf_r), FUNC(pce_state::cd_intf_w)); } void pce_state::pce_io(address_map &map) @@ -100,16 +130,16 @@ void pce_state::pce_io(address_map &map) void pce_state::sgx_mem(address_map &map) { - map(0x100000, 0x10FFFF).ram().share("cd_ram"); - map(0x110000, 0x1EDFFF).noprw(); - map(0x1EE000, 0x1EE7FF).rw(m_cd, FUNC(pce_cd_device::bram_r), FUNC(pce_cd_device::bram_w)); - map(0x1EE800, 0x1EFFFF).noprw(); - map(0x1F0000, 0x1F7FFF).ram(); - map(0x1FE000, 0x1FE007).rw("huc6270_0", FUNC(huc6270_device::read), FUNC(huc6270_device::write)).mirror(0x03E0); - map(0x1FE008, 0x1FE00F).rw("huc6202", FUNC(huc6202_device::read), FUNC(huc6202_device::write)).mirror(0x03E0); - map(0x1FE010, 0x1FE017).rw("huc6270_1", FUNC(huc6270_device::read), FUNC(huc6270_device::write)).mirror(0x03E0); - map(0x1FE400, 0x1FE7FF).rw(m_huc6260, FUNC(huc6260_device::read), FUNC(huc6260_device::write)); - map(0x1FF800, 0x1FFBFF).rw(FUNC(pce_state::cd_intf_r), FUNC(pce_state::cd_intf_w)); + map(0x100000, 0x10ffff).ram().share("cd_ram"); + map(0x110000, 0x1edfff).noprw(); + map(0x1ee000, 0x1ee7ff).rw(m_cd, FUNC(pce_cd_device::bram_r), FUNC(pce_cd_device::bram_w)); + map(0x1ee800, 0x1effff).noprw(); + map(0x1f0000, 0x1f7fff).ram(); + map(0x1fe000, 0x1fe007).rw("huc6270_0", FUNC(huc6270_device::read), FUNC(huc6270_device::write)).mirror(0x03e0); + map(0x1fe008, 0x1fe00f).rw("huc6202", FUNC(huc6202_device::read), FUNC(huc6202_device::write)).mirror(0x03e0); + map(0x1fe010, 0x1fe017).rw("huc6270_1", FUNC(huc6270_device::read), FUNC(huc6270_device::write)).mirror(0x03e0); + map(0x1fe400, 0x1fe7ff).rw(m_huc6260, FUNC(huc6260_device::read), FUNC(huc6260_device::write)); + map(0x1ff800, 0x1ffbff).rw(FUNC(pce_state::cd_intf_r), FUNC(pce_state::cd_intf_w)); } @@ -126,6 +156,20 @@ uint32_t pce_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, c } +void pce_state::machine_start() +{ + if (m_cd) + m_cd->late_setup(); + + // saving is only partially supported: it should be fine with cart games + // OTOH CD states are saved but not correctly restored! + save_item(NAME(m_io_port_options)); +} + +void pce_state::machine_reset() +{ +} + static void pce_cart(device_slot_interface &device) { device.option_add_internal("rom", PCE_ROM_STD); @@ -176,6 +220,8 @@ void pce_state::pce_common(machine_config &config) PCE_CD(config, m_cd, 0); m_cd->irq().set_inputline(m_maincpu, 1); m_cd->set_maincpu(m_maincpu); + m_cd->add_route(0, "lspeaker", 1.0); + m_cd->add_route(1, "rspeaker", 1.0); SOFTWARE_LIST(config, "cd_list").set_original("pcecd"); } @@ -266,6 +312,8 @@ void pce_state::sgx(machine_config &config) PCE_CD(config, m_cd, 0); m_cd->irq().set_inputline(m_maincpu, 1); m_cd->set_maincpu(m_maincpu); + m_cd->add_route(0, "lspeaker", 1.0); + m_cd->add_route(1, "rspeaker", 1.0); SOFTWARE_LIST(config, "cd_list").set_original("pcecd"); } @@ -283,6 +331,16 @@ ROM_END #define rom_tg16 rom_pce #define rom_sgx rom_pce +void pce_state::init_pce() +{ + m_io_port_options = PCE_JOY_SIG | CONST_SIG; +} + +void pce_state::init_tg16() +{ + m_io_port_options = TG_16_JOY_SIG | CONST_SIG; +} + CONS( 1987, pce, 0, 0, pce, pce, pce_state, init_pce, "NEC / Hudson Soft", "PC Engine", MACHINE_IMPERFECT_SOUND ) CONS( 1989, tg16, pce, 0, tg16, pce, pce_state, init_tg16, "NEC / Hudson Soft", "TurboGrafx-16", MACHINE_IMPERFECT_SOUND ) CONS( 1989, sgx, pce, 0, sgx, pce, pce_state, init_pce, "NEC / Hudson Soft", "SuperGrafx", MACHINE_IMPERFECT_SOUND ) diff --git a/src/mame/nec/pce.h b/src/mame/nec/pce.h index 87d4d24cf62..1ce4d9e32a6 100644 --- a/src/mame/nec/pce.h +++ b/src/mame/nec/pce.h @@ -21,26 +21,12 @@ #include "cdrom.h" -#define C6280_TAG "c6280" - -#define MAIN_CLOCK 21477270 - -#define TG_16_JOY_SIG 0x00 -#define PCE_JOY_SIG 0x40 -#define NO_CD_SIG 0x80 -#define CD_SIG 0x00 -/* these might be used to indicate something, but they always seem to return 1 */ -#define CONST_SIG 0x30 - - - class pce_state : public driver_device { public: pce_state(const machine_config &mconfig, device_type type, const char *tag) : driver_device(mconfig, type, tag), m_maincpu(*this, "maincpu"), - m_cd_ram(*this, "cd_ram"), m_huc6260(*this, "huc6260"), m_cartslot(*this, "cartslot"), m_cd(*this, "pce_cd"), @@ -61,7 +47,6 @@ protected: private: required_device m_maincpu; - required_shared_ptr m_cd_ram; required_device m_huc6260; required_device m_cartslot; optional_device m_cd; diff --git a/src/mame/nec/pce_cd.cpp b/src/mame/nec/pce_cd.cpp index 9ee6127ce63..87ec67f3018 100644 --- a/src/mame/nec/pce_cd.cpp +++ b/src/mame/nec/pce_cd.cpp @@ -53,7 +53,7 @@ TODO: #define LIVE_SUBQ_VIEW 0 #define LIVE_ADPCM_VIEW 0 -#define PCE_CD_CLOCK 9216000 +static constexpr XTAL PCE_CD_CLOCK = XTAL(9'216'000); // TODO: correct name, split into incremental HuCard slot devices @@ -82,6 +82,7 @@ void pce_cd_device::regs_map(address_map &map) pce_cd_device::pce_cd_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, PCE_CD, tag, owner, clock) , device_memory_interface(mconfig, *this) + , device_mixer_interface(mconfig, *this, 2) , m_space_config("io", ENDIANNESS_LITTLE, 8, 4, 0, address_map_constructor(FUNC(pce_cd_device::regs_map), this)) , m_maincpu(*this, finder_base::DUMMY_TAG) , m_irq_cb(*this) @@ -262,14 +263,14 @@ void pce_cd_device::device_add_mconfig(machine_config &config) MSM5205(config, m_msm, PCE_CD_CLOCK / 6); m_msm->vck_legacy_callback().set(FUNC(pce_cd_device::msm5205_int)); /* interrupt function */ m_msm->set_prescaler_selector(msm5205_device::S48_4B); /* 1/48 prescaler, 4bit data */ - m_msm->add_route(ALL_OUTPUTS, "^lspeaker", 0.50); - m_msm->add_route(ALL_OUTPUTS, "^rspeaker", 0.50); + m_msm->add_route(ALL_OUTPUTS, *this, 0.50, AUTO_ALLOC_INPUT, 0); + m_msm->add_route(ALL_OUTPUTS, *this, 0.50, AUTO_ALLOC_INPUT, 1); CDDA(config, m_cdda); m_cdda->set_cdrom_tag(m_cdrom); m_cdda->audio_end_cb().set(FUNC(pce_cd_device::cdda_end_mark_cb)); - m_cdda->add_route(0, "^lspeaker", 1.00); - m_cdda->add_route(1, "^rspeaker", 1.00); + m_cdda->add_route(0, *this, 1.00, AUTO_ALLOC_INPUT, 0); + m_cdda->add_route(1, *this, 1.00, AUTO_ALLOC_INPUT, 1); } void pce_cd_device::adpcm_stop(uint8_t irq_flag) diff --git a/src/mame/nec/pce_cd.h b/src/mame/nec/pce_cd.h index 4fdd6e0ddfd..3c6c9ed470a 100644 --- a/src/mame/nec/pce_cd.h +++ b/src/mame/nec/pce_cd.h @@ -14,34 +14,13 @@ #include "sound/cdda.h" #include "sound/msm5205.h" -#define PCE_BRAM_SIZE 0x800 -#define PCE_ADPCM_RAM_SIZE 0x10000 -#define PCE_ACARD_RAM_SIZE 0x200000 -#define PCE_CD_COMMAND_BUFFER_SIZE 0x100 - -#define PCE_CD_IRQ_TRANSFER_READY 0x40 -#define PCE_CD_IRQ_TRANSFER_DONE 0x20 -#define PCE_CD_IRQ_BRAM 0x10 /* ??? */ -#define PCE_CD_IRQ_SAMPLE_FULL_PLAY 0x08 -#define PCE_CD_IRQ_SAMPLE_HALF_PLAY 0x04 - -#define PCE_CD_ADPCM_PLAY_FLAG 0x08 -#define PCE_CD_ADPCM_STOP_FLAG 0x01 - -#define PCE_CD_DATA_FRAMES_PER_SECOND 75 - -enum { - PCE_CD_CDDA_OFF = 0, - PCE_CD_CDDA_PLAYING, - PCE_CD_CDDA_PAUSED -}; - // ======================> pce_cd_device class pce_cd_device : public device_t, - public device_memory_interface + public device_memory_interface, + public device_mixer_interface { public: // construction/destruction @@ -68,6 +47,27 @@ protected: virtual space_config_vector memory_space_config() const override; private: + static constexpr size_t PCE_BRAM_SIZE = 0x800; + static constexpr size_t PCE_ADPCM_RAM_SIZE = 0x10000; + static constexpr size_t PCE_CD_COMMAND_BUFFER_SIZE = 0x100; + + static constexpr uint8_t PCE_CD_IRQ_TRANSFER_READY = 0x40; + static constexpr uint8_t PCE_CD_IRQ_TRANSFER_DONE = 0x20; + static constexpr uint8_t PCE_CD_IRQ_BRAM = 0x10; /* ??? */ + static constexpr uint8_t PCE_CD_IRQ_SAMPLE_FULL_PLAY = 0x08; + static constexpr uint8_t PCE_CD_IRQ_SAMPLE_HALF_PLAY = 0x04; + + static constexpr uint8_t PCE_CD_ADPCM_PLAY_FLAG = 0x08; + static constexpr uint8_t PCE_CD_ADPCM_STOP_FLAG = 0x01; + + static constexpr int PCE_CD_DATA_FRAMES_PER_SECOND = 75; + + enum { + PCE_CD_CDDA_OFF = 0, + PCE_CD_CDDA_PLAYING, + PCE_CD_CDDA_PAUSED + }; + const address_space_config m_space_config; uint8_t cdc_status_r(); diff --git a/src/mame/nec/pce_m.cpp b/src/mame/nec/pce_m.cpp deleted file mode 100644 index deef178979d..00000000000 --- a/src/mame/nec/pce_m.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Charles MacDonald, Wilbert Pol, Angelo Salese -/************************************************************************************************** - -PC Engine legacy middle ground file, to be removed ... - -**************************************************************************************************/ - -#include "emu.h" -#include "cpu/h6280/h6280.h" -#include "pce.h" - - -void pce_state::init_pce() -{ - m_io_port_options = PCE_JOY_SIG | CONST_SIG; -} - -void pce_state::init_tg16() -{ - m_io_port_options = TG_16_JOY_SIG | CONST_SIG; -} - -void pce_state::machine_start() -{ - if (m_cd) - m_cd->late_setup(); - - // saving is only partially supported: it should be fine with cart games - // OTOH CD states are saved but not correctly restored! - save_item(NAME(m_io_port_options)); -} - -void pce_state::machine_reset() -{ -} - -void pce_state::controller_w(u8 data) -{ - m_port_ctrl->sel_w(BIT(data, 0)); - m_port_ctrl->clr_w(BIT(data, 1)); -} - -u8 pce_state::controller_r() -{ - u8 ret = (m_port_ctrl->port_r() & 0x0f) | m_io_port_options; -#ifdef UNIFIED_PCE - ret &= ~0x40; -#endif - - return ret; -} - - -void pce_state::cd_intf_w(offs_t offset, u8 data) -{ - m_cd->update(); - - m_cd->intf_w(offset, data); - - m_cd->update(); -} - -u8 pce_state::cd_intf_r(offs_t offset) -{ - m_cd->update(); - - return m_cd->intf_r(offset); -} -- cgit v1.2.3