Skip to content

Commit

Permalink
nmk/nmk004.cpp, nmk/nmk16.cpp: Cleaned up code: (#13173)
Browse files Browse the repository at this point in the history
* nmk/nmk004.cpp: Removed hard-coded assumptions about surrounding system.
* nmk/nmk16.cpp: Suppress side effects for debugger reads, improved save state support.
* nmk/nmk16.cpp: Removed unused variables, reduced use of literal tags, added notes.
  • Loading branch information
cam900 authored Jan 7, 2025
1 parent 44284c5 commit adc1620
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 245 deletions.
67 changes: 46 additions & 21 deletions src/mame/nmk/nmk004.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,33 @@ void nmk004_device::port4_w(uint8_t data)
m_reset_cb(BIT(data, 0) ? ASSERT_LINE : CLEAR_LINE);
}

void nmk004_device::oki0_bankswitch_w(uint8_t data)
uint8_t nmk004_device::ym_r(offs_t offset)
{
data &= 3;
membank(":okibank1")->set_entry(data);
return m_ym_read_cb(offset);
}

void nmk004_device::ym_w(offs_t offset, uint8_t data)
{
m_ym_write_cb(offset, data);
}

template <unsigned Which>
uint8_t nmk004_device::oki_r()
{
return m_oki_read_cb[Which]();
}

template <unsigned Which>
void nmk004_device::oki_w(uint8_t data)
{
m_oki_write_cb[Which](data);
}

void nmk004_device::oki1_bankswitch_w(uint8_t data)
template <unsigned Which>
void nmk004_device::oki_bankswitch_w(uint8_t data)
{
data &= 3;
membank(":okibank2")->set_entry(data);
m_okibank[Which]->set_entry(data);
}

uint8_t nmk004_device::tonmk004_r()
Expand All @@ -63,18 +80,18 @@ void nmk004_device::ym2203_irq_handler(int irq)
m_cpu->set_input_line(0, irq ? ASSERT_LINE : CLEAR_LINE);
}

void nmk004_device::nmk004_sound_mem_map(address_map &map)
void nmk004_device::mem_map(address_map &map)
{
//map(0x0000, 0x1fff).rom(); /* 0x0000 - 0x1fff = internal ROM */
map(0x2000, 0xefff).rom().region(":audiocpu", 0x2000);
map(0x2000, 0xefff).rom().region(DEVICE_SELF, 0x2000);
map(0xf000, 0xf7ff).ram();
map(0xf800, 0xf801).rw(":ymsnd", FUNC(ym2203_device::read), FUNC(ym2203_device::write));
map(0xf900, 0xf900).rw(":oki1", FUNC(okim6295_device::read), FUNC(okim6295_device::write));
map(0xfa00, 0xfa00).rw(":oki2", FUNC(okim6295_device::read), FUNC(okim6295_device::write));
map(0xf800, 0xf801).rw(FUNC(nmk004_device::ym_r), FUNC(nmk004_device::ym_w));
map(0xf900, 0xf900).rw(FUNC(nmk004_device::oki_r<0>), FUNC(nmk004_device::oki_w<0>));
map(0xfa00, 0xfa00).rw(FUNC(nmk004_device::oki_r<1>), FUNC(nmk004_device::oki_w<1>));
map(0xfb00, 0xfb00).r(FUNC(nmk004_device::tonmk004_r)); // from main cpu
map(0xfc00, 0xfc00).w(FUNC(nmk004_device::tomain_w)); // to main cpu
map(0xfc01, 0xfc01).w(FUNC(nmk004_device::oki0_bankswitch_w));
map(0xfc02, 0xfc02).w(FUNC(nmk004_device::oki1_bankswitch_w));
map(0xfc01, 0xfc01).w(FUNC(nmk004_device::oki_bankswitch_w<0>));
map(0xfc02, 0xfc02).w(FUNC(nmk004_device::oki_bankswitch_w<1>));
}


Expand All @@ -87,11 +104,17 @@ ROM_END
DEFINE_DEVICE_TYPE(NMK004, nmk004_device, "nmk004", "NMK004")

nmk004_device::nmk004_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: device_t(mconfig, NMK004, tag, owner, clock),
m_cpu(*this, "mcu"),
m_reset_cb(*this),
to_nmk004(0xff),
to_main(0xff)
: device_t(mconfig, NMK004, tag, owner, clock)
, m_cpu(*this, "mcu")
, m_okirom(*this, {finder_base::DUMMY_TAG, finder_base::DUMMY_TAG})
, m_okibank(*this, {finder_base::DUMMY_TAG, finder_base::DUMMY_TAG})
, m_reset_cb(*this)
, m_ym_read_cb(*this, 0)
, m_ym_write_cb(*this)
, m_oki_read_cb{{*this, 0}, {*this, 0}}
, m_oki_write_cb{{*this}, {*this}}
, to_nmk004(0xff)
, to_main(0xff)
{
}

Expand All @@ -104,8 +127,10 @@ void nmk004_device::device_start()
save_item(NAME(to_main));
save_item(NAME(to_nmk004));

membank(":okibank1")->configure_entries(0, 4, memregion(":oki1")->base() + 0x20000, 0x20000);
membank(":okibank2")->configure_entries(0, 4, memregion(":oki2")->base() + 0x20000, 0x20000);
for (int i = 0; i < 2; i++)
{
m_okibank[i]->configure_entries(0, 4, m_okirom[i] + 0x20000, 0x20000);
}
}

//-------------------------------------------------
Expand All @@ -114,7 +139,7 @@ void nmk004_device::device_start()
void nmk004_device::device_add_mconfig(machine_config &config)
{
TMP90840(config, m_cpu, DERIVED_CLOCK(1,1)); // Toshiba TMP90C840AF in QFP64 package with 8Kbyte internal ROM
m_cpu->set_addrmap(AS_PROGRAM, &nmk004_device::nmk004_sound_mem_map);
m_cpu->set_addrmap(AS_PROGRAM, &nmk004_device::mem_map);
m_cpu->port_write<4>().set(FUNC(nmk004_device::port4_w));
}

Expand All @@ -124,5 +149,5 @@ void nmk004_device::device_add_mconfig(machine_config &config)
//-------------------------------------------------
const tiny_rom_entry *nmk004_device::device_rom_region() const
{
return ROM_NAME(nmk004 );
return ROM_NAME(nmk004);
}
38 changes: 32 additions & 6 deletions src/mame/nmk/nmk004.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,30 @@ class nmk004_device : public device_t
public:
nmk004_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

// configuration
auto reset_cb() { return m_reset_cb.bind(); }
template <typename T, typename U> void set_rom_tag(T &&tag1, U &&tag2)
{
m_okirom[0].set_tag(std::forward<T>(tag1));
m_okirom[1].set_tag(std::forward<U>(tag2));
}
template <typename T, typename U> void set_rombank_tag(T &&tag1, U &&tag2)
{
m_okibank[0].set_tag(std::forward<T>(tag1));
m_okibank[1].set_tag(std::forward<U>(tag2));
}
auto ym_read_callback() { return m_ym_read_cb.bind(); }
auto ym_write_callback() { return m_ym_write_cb.bind(); }
template <unsigned Which> auto oki_read_callback() { return m_oki_read_cb[Which].bind(); }
template <unsigned Which> auto oki_write_callback() { return m_oki_write_cb[Which].bind(); }

// host interface
void write(uint8_t data);
uint8_t read();
void nmi_w(int state) { m_cpu->set_input_line(INPUT_LINE_NMI, state); }

void port4_w(uint8_t data);
void ym2203_irq_handler(int irq);

void nmk004_sound_mem_map(address_map &map) ATTR_COLD;
protected:
// device-level overrides
virtual void device_start() override ATTR_COLD;
Expand All @@ -37,16 +50,29 @@ class nmk004_device : public device_t

private:
// internal state
required_device<tlcs90_device> m_cpu;
devcb_write_line m_reset_cb;
required_device<tlcs90_device> m_cpu;
required_region_ptr_array<uint8_t, 2> m_okirom;
required_memory_bank_array<2> m_okibank;
devcb_write_line m_reset_cb;
devcb_read8 m_ym_read_cb;
devcb_write8 m_ym_write_cb;
devcb_read8 m_oki_read_cb[2];
devcb_write8 m_oki_write_cb[2];

uint8_t to_nmk004;
uint8_t to_main;

void oki0_bankswitch_w(uint8_t data);
void oki1_bankswitch_w(uint8_t data);
template <unsigned Which> void oki_bankswitch_w(uint8_t data);
uint8_t ym_r(offs_t offset);
void ym_w(offs_t offset, uint8_t data);
template <unsigned Which> uint8_t oki_r();
template <unsigned Which> void oki_w(uint8_t data);
uint8_t tonmk004_r();
void tomain_w(uint8_t data);

void port4_w(uint8_t data);

void mem_map(address_map &map) ATTR_COLD;
};

DECLARE_DEVICE_TYPE(NMK004, nmk004_device)
Expand Down
Loading

0 comments on commit adc1620

Please sign in to comment.