Skip to content

Conversation

cam900
Copy link
Contributor

@cam900 cam900 commented Oct 5, 2025

  • Reduce duplicates
  • Fix spacings and argument data type
  • atlus/cave.cpp, atlus/patapata.cpp, nmk/nmk16.cpp, nmk/nmkmedal.cpp, nmk/quizpani.cpp: Fix memory region size for NMK112 bankswitched OKI MSM6295 spaces

cam900 added 2 commits October 5, 2025 17:51
…address_space

- Reduce duplicates
- Fix spacings and argument data type
- atlus/cave.cpp, atlus/patapata.cpp, nmk/nmk16.cpp, nmk/nmkmedal.cpp, nmk/quizpani.cpp: Fix memory region size for NMK112 bankswitched OKI MSM6295 spaces
Copy link
Member

@cuavas cuavas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change to use real bank objects is a good idea, but I don’t think the method of installing into address spaces is ideal. Rather than adding the address space finders to the NMK112 device, you should add address map functions, e.g. something like:

In machine/nmk112.h:

...
class nmk112_device : public device_t
{
public:
...
	void oki0(address_map &map) ATTR_COLD;
	void oki1(address_map &map) ATTR_COLD;
...
private:
...
	void oki_map(address_map &map, unsigned which) ATTR_COLD;
...
};
...

In machine/nmk112.cpp:

...
void nmk112_device::oki0(address_map &map)
{
	oki_map(map, 0);
}

void nmk112_device::oki1(address_map &map)
{
	oki_map(map, 1);
}

void nmk112_device::oki_map(address_map &map, unsigned which)
{
	for (int i = 0; i < 4; i++)
	{
		map((i << 16) | page_offset(which, i), (i << 16) | 0xffff).bankr(m_samplebank[which][i]);
		if (paged)
			map(i << 8, (i << 8) | 0xff).bankr(m_tablebank[which][i]);
	}
}
...

Then when you want use it in a driver, you can do something like:

...
void cave_state::donpachi(machine_config &config)
{
...
	OKIM6295(config, m_oki[0], 4.220_MHz_XTAL/4, okim6295_device::PIN7_HIGH); // pin 7 not verified
	m_oki[0]->add_route(ALL_OUTPUTS, "mono", 1.60);

	OKIM6295(config, m_oki[1], 4.220_MHz_XTAL/2, okim6295_device::PIN7_HIGH); // pin 7 not verified
	m_oki[1]->add_route(ALL_OUTPUTS, "mono", 1.0);

	nmk112_device &nmk112(NMK112(config, "nmk112", 0));
	nmk112.set_rom0_tag("oki1");
	nmk112.set_rom1_tag("oki2");
	nmk112.set_page_mask(1 << 0);    // chip #0 (music) is not paged
	m_oki[0]->set_addrmap(0, nmk112, &nmk112_device::oki0);
	m_oki[1]->set_addrmap(0, nmk112, &nmk112_device::oki1);
}

This isn’t tested, and I’m coding in a web browser, but I hope you can see the basic idea.

@cam900
Copy link
Contributor Author

cam900 commented Oct 5, 2025

The change to use real bank objects is a good idea, but I don’t think the method of installing into address spaces is ideal. Rather than adding the address space finders to the NMK112 device, you should add address map functions, e.g. something like:

In machine/nmk112.h:

...
class nmk112_device : public device_t
{
public:
...
	void oki0(address_map &map) ATTR_COLD;
	void oki1(address_map &map) ATTR_COLD;
...
private:
...
	void oki_map(address_map &map, unsigned which) ATTR_COLD;
...
};
...

In machine/nmk112.cpp:

...
void nmk112_device::oki0(address_map &map)
{
	oki_map(map, 0);
}

void nmk112_device::oki1(address_map &map)
{
	oki_map(map, 1);
}

void nmk112_device::oki_map(address_map &map, unsigned which)
{
	for (int i = 0; i < 4; i++)
	{
		map((i << 16) | page_offset(which, i), (i << 16) | 0xffff).bankr(m_samplebank[which][i]);
		if (paged)
			map(i << 8, (i << 8) | 0xff).bankr(m_tablebank[which][i]);
	}
}
...

Then when you want use it in a driver, you can do something like:

...
void cave_state::donpachi(machine_config &config)
{
...
	OKIM6295(config, m_oki[0], 4.220_MHz_XTAL/4, okim6295_device::PIN7_HIGH); // pin 7 not verified
	m_oki[0]->add_route(ALL_OUTPUTS, "mono", 1.60);

	OKIM6295(config, m_oki[1], 4.220_MHz_XTAL/2, okim6295_device::PIN7_HIGH); // pin 7 not verified
	m_oki[1]->add_route(ALL_OUTPUTS, "mono", 1.0);

	nmk112_device &nmk112(NMK112(config, "nmk112", 0));
	nmk112.set_rom0_tag("oki1");
	nmk112.set_rom1_tag("oki2");
	nmk112.set_page_mask(1 << 0);    // chip #0 (music) is not paged
	m_oki[0]->set_addrmap(0, nmk112, &nmk112_device::oki0);
	m_oki[1]->set_addrmap(0, nmk112, &nmk112_device::oki1);
}

This isn’t tested, and I’m coding in a web browser, but I hope you can see the basic idea.

Simply crash when OKI chip tries to play sample because address map is installed before ROM related stuff is initialized.

Bank initialization function is should be moved from device_start?

@cuavas
Copy link
Member

cuavas commented Oct 6, 2025

Simply crash when OKI chip tries to play sample because address map is installed before ROM related stuff is initialized.

Which part is crashing? The address map function should be able to use bankr before the bank entries are set up. Just setting up where the banked memory is located in the address map doesn’t cause bank entries to be accessed. The address map function shouldn’t need to access anything that depends on having the ROM available.

Bank initialization function is should be moved from device_start?

No, the actual part where you call configure_entry etc. to set up the bank entries should happen at device_start time because you won’t have all your object finders resolved before that.

@cam900
Copy link
Contributor Author

cam900 commented Oct 6, 2025

Which part is crashing? The address map function should be able to use bankr before the bank entries are set up. Just setting up where the banked memory is located in the address map doesn’t cause bank entries to be accessed. The address map function shouldn’t need to access anything that depends on having the ROM available.

When tries to access sample space from method of above. Memory bank finder should be optional_memory_bank_array for use bankr?

@cuavas
Copy link
Member

cuavas commented Oct 6, 2025

Which part is crashing? The address map function should be able to use bankr before the bank entries are set up. Just setting up where the banked memory is located in the address map doesn’t cause bank entries to be accessed. The address map function shouldn’t need to access anything that depends on having the ROM available.

When tries to access sample space from method of above. Memory bank finder should be optional_memory_bank_array for use bankr?

bankr should work with memory_bank_array_creator or optional_memory_bank_array. I’ll look at it later, maybe I’m forgetting something important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants