Skip to content

Commit adc1620

Browse files
authored
nmk/nmk004.cpp, nmk/nmk16.cpp: Cleaned up code: (#13173)
* 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.
1 parent 44284c5 commit adc1620

File tree

5 files changed

+316
-245
lines changed

5 files changed

+316
-245
lines changed

src/mame/nmk/nmk004.cpp

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,33 @@ void nmk004_device::port4_w(uint8_t data)
3333
m_reset_cb(BIT(data, 0) ? ASSERT_LINE : CLEAR_LINE);
3434
}
3535

36-
void nmk004_device::oki0_bankswitch_w(uint8_t data)
36+
uint8_t nmk004_device::ym_r(offs_t offset)
3737
{
38-
data &= 3;
39-
membank(":okibank1")->set_entry(data);
38+
return m_ym_read_cb(offset);
39+
}
40+
41+
void nmk004_device::ym_w(offs_t offset, uint8_t data)
42+
{
43+
m_ym_write_cb(offset, data);
44+
}
45+
46+
template <unsigned Which>
47+
uint8_t nmk004_device::oki_r()
48+
{
49+
return m_oki_read_cb[Which]();
50+
}
51+
52+
template <unsigned Which>
53+
void nmk004_device::oki_w(uint8_t data)
54+
{
55+
m_oki_write_cb[Which](data);
4056
}
4157

42-
void nmk004_device::oki1_bankswitch_w(uint8_t data)
58+
template <unsigned Which>
59+
void nmk004_device::oki_bankswitch_w(uint8_t data)
4360
{
4461
data &= 3;
45-
membank(":okibank2")->set_entry(data);
62+
m_okibank[Which]->set_entry(data);
4663
}
4764

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

66-
void nmk004_device::nmk004_sound_mem_map(address_map &map)
83+
void nmk004_device::mem_map(address_map &map)
6784
{
6885
//map(0x0000, 0x1fff).rom(); /* 0x0000 - 0x1fff = internal ROM */
69-
map(0x2000, 0xefff).rom().region(":audiocpu", 0x2000);
86+
map(0x2000, 0xefff).rom().region(DEVICE_SELF, 0x2000);
7087
map(0xf000, 0xf7ff).ram();
71-
map(0xf800, 0xf801).rw(":ymsnd", FUNC(ym2203_device::read), FUNC(ym2203_device::write));
72-
map(0xf900, 0xf900).rw(":oki1", FUNC(okim6295_device::read), FUNC(okim6295_device::write));
73-
map(0xfa00, 0xfa00).rw(":oki2", FUNC(okim6295_device::read), FUNC(okim6295_device::write));
88+
map(0xf800, 0xf801).rw(FUNC(nmk004_device::ym_r), FUNC(nmk004_device::ym_w));
89+
map(0xf900, 0xf900).rw(FUNC(nmk004_device::oki_r<0>), FUNC(nmk004_device::oki_w<0>));
90+
map(0xfa00, 0xfa00).rw(FUNC(nmk004_device::oki_r<1>), FUNC(nmk004_device::oki_w<1>));
7491
map(0xfb00, 0xfb00).r(FUNC(nmk004_device::tonmk004_r)); // from main cpu
7592
map(0xfc00, 0xfc00).w(FUNC(nmk004_device::tomain_w)); // to main cpu
76-
map(0xfc01, 0xfc01).w(FUNC(nmk004_device::oki0_bankswitch_w));
77-
map(0xfc02, 0xfc02).w(FUNC(nmk004_device::oki1_bankswitch_w));
93+
map(0xfc01, 0xfc01).w(FUNC(nmk004_device::oki_bankswitch_w<0>));
94+
map(0xfc02, 0xfc02).w(FUNC(nmk004_device::oki_bankswitch_w<1>));
7895
}
7996

8097

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

89106
nmk004_device::nmk004_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
90-
: device_t(mconfig, NMK004, tag, owner, clock),
91-
m_cpu(*this, "mcu"),
92-
m_reset_cb(*this),
93-
to_nmk004(0xff),
94-
to_main(0xff)
107+
: device_t(mconfig, NMK004, tag, owner, clock)
108+
, m_cpu(*this, "mcu")
109+
, m_okirom(*this, {finder_base::DUMMY_TAG, finder_base::DUMMY_TAG})
110+
, m_okibank(*this, {finder_base::DUMMY_TAG, finder_base::DUMMY_TAG})
111+
, m_reset_cb(*this)
112+
, m_ym_read_cb(*this, 0)
113+
, m_ym_write_cb(*this)
114+
, m_oki_read_cb{{*this, 0}, {*this, 0}}
115+
, m_oki_write_cb{{*this}, {*this}}
116+
, to_nmk004(0xff)
117+
, to_main(0xff)
95118
{
96119
}
97120

@@ -104,8 +127,10 @@ void nmk004_device::device_start()
104127
save_item(NAME(to_main));
105128
save_item(NAME(to_nmk004));
106129

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

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

@@ -124,5 +149,5 @@ void nmk004_device::device_add_mconfig(machine_config &config)
124149
//-------------------------------------------------
125150
const tiny_rom_entry *nmk004_device::device_rom_region() const
126151
{
127-
return ROM_NAME(nmk004 );
152+
return ROM_NAME(nmk004);
128153
}

src/mame/nmk/nmk004.h

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,30 @@ class nmk004_device : public device_t
1818
public:
1919
nmk004_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
2020

21+
// configuration
2122
auto reset_cb() { return m_reset_cb.bind(); }
23+
template <typename T, typename U> void set_rom_tag(T &&tag1, U &&tag2)
24+
{
25+
m_okirom[0].set_tag(std::forward<T>(tag1));
26+
m_okirom[1].set_tag(std::forward<U>(tag2));
27+
}
28+
template <typename T, typename U> void set_rombank_tag(T &&tag1, U &&tag2)
29+
{
30+
m_okibank[0].set_tag(std::forward<T>(tag1));
31+
m_okibank[1].set_tag(std::forward<U>(tag2));
32+
}
33+
auto ym_read_callback() { return m_ym_read_cb.bind(); }
34+
auto ym_write_callback() { return m_ym_write_cb.bind(); }
35+
template <unsigned Which> auto oki_read_callback() { return m_oki_read_cb[Which].bind(); }
36+
template <unsigned Which> auto oki_write_callback() { return m_oki_write_cb[Which].bind(); }
2237

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

28-
void port4_w(uint8_t data);
2943
void ym2203_irq_handler(int irq);
3044

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

3851
private:
3952
// internal state
40-
required_device<tlcs90_device> m_cpu;
41-
devcb_write_line m_reset_cb;
53+
required_device<tlcs90_device> m_cpu;
54+
required_region_ptr_array<uint8_t, 2> m_okirom;
55+
required_memory_bank_array<2> m_okibank;
56+
devcb_write_line m_reset_cb;
57+
devcb_read8 m_ym_read_cb;
58+
devcb_write8 m_ym_write_cb;
59+
devcb_read8 m_oki_read_cb[2];
60+
devcb_write8 m_oki_write_cb[2];
4261

4362
uint8_t to_nmk004;
4463
uint8_t to_main;
4564

46-
void oki0_bankswitch_w(uint8_t data);
47-
void oki1_bankswitch_w(uint8_t data);
65+
template <unsigned Which> void oki_bankswitch_w(uint8_t data);
66+
uint8_t ym_r(offs_t offset);
67+
void ym_w(offs_t offset, uint8_t data);
68+
template <unsigned Which> uint8_t oki_r();
69+
template <unsigned Which> void oki_w(uint8_t data);
4870
uint8_t tonmk004_r();
4971
void tomain_w(uint8_t data);
72+
73+
void port4_w(uint8_t data);
74+
75+
void mem_map(address_map &map) ATTR_COLD;
5076
};
5177

5278
DECLARE_DEVICE_TYPE(NMK004, nmk004_device)

0 commit comments

Comments
 (0)