Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nec/pce.cpp, nec/pce_cd.cpp: Various updates #11999

Merged
merged 5 commits into from Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
106 changes: 82 additions & 24 deletions src/mame/nec/pce.cpp
Expand Up @@ -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)
Expand All @@ -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));
}


Expand All @@ -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);
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand All @@ -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 )
Expand Down
15 changes: 0 additions & 15 deletions src/mame/nec/pce.h
Expand Up @@ -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"),
Expand All @@ -61,7 +47,6 @@ class pce_state : public driver_device

private:
required_device<h6280_device> m_maincpu;
required_shared_ptr<u8> m_cd_ram;
required_device<huc6260_device> m_huc6260;
required_device<pce_cart_slot_device> m_cartslot;
optional_device<pce_cd_device> m_cd;
Expand Down
11 changes: 6 additions & 5 deletions src/mame/nec/pce_cd.cpp
Expand Up @@ -53,7 +53,7 @@ PC Engine CD HW sub-portion:
#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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
46 changes: 23 additions & 23 deletions src/mame/nec/pce_cd.h
Expand Up @@ -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
Expand All @@ -68,6 +47,27 @@ class pce_cd_device : public device_t,
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();
Expand Down
69 changes: 0 additions & 69 deletions src/mame/nec/pce_m.cpp

This file was deleted.