summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author sasuke-arcade <58130089+sasuke-arcade@users.noreply.github.com>2021-04-18 04:19:56 +0900
committer GitHub <noreply@github.com>2021-04-17 21:19:56 +0200
commitfdb43e616be4336a080028422408fc4fd87a76e9 (patch)
treefcf21a07e8c1e7e04c3ac6bde56f2a03465b48fa
parent667fa4e7a97f9a8b848652922462f7436aef0fa3 (diff)
nb1412m2: Fixed some Mighty Guy sound issues (#7961)
Fixed various sound issues in Mighty Guy so that it sounds almost exactly like PCB. - Fixed BGM tempo was unstable. The frequency setting of DAC and timer clock are now linked. When changes the DAC clock, Sound driver set wait loop count ($C010) in the range of 2 to 4 in order to keep the tempo of BGM even if changed clock. This was the cause of the slow BGM in previous versions. - Fixed DAC clock calculation. I changed this so that sound plays same as PCB. - Implemented a protect command 0x11 to stop the DAC. This is needed to stop DAC sound when the psycho gun is stopped.
-rw-r--r--src/mame/machine/nb1412m2.cpp28
-rw-r--r--src/mame/machine/nb1412m2.h4
2 files changed, 22 insertions, 10 deletions
diff --git a/src/mame/machine/nb1412m2.cpp b/src/mame/machine/nb1412m2.cpp
index 0a4edfb590c..362f80eb959 100644
--- a/src/mame/machine/nb1412m2.cpp
+++ b/src/mame/machine/nb1412m2.cpp
@@ -14,8 +14,6 @@ It is unknown at current stage if inside the chip there's a MCU
(with internal ROM).
TODO:
-- main sound timer is "jumpy" (like BGM tempo gets screwy then fixes itself somehow),
- fiddling with port 0x90 seems to improve things, why?
- DAC timer is guessworked;
Legacy notes from drivers:
@@ -104,7 +102,7 @@ void nb1412m2_device::nb1412m2_map(address_map &map)
map(0x42, 0x43).nopw(); // always 0x03
// DAC control
- map(0x11, 0x11).nopw(); // - unknown (volume/channel control?)
+ map(0x11, 0x11).w(FUNC(nb1412m2_device::dac_control_w));
map(0x18, 0x18).w(FUNC(nb1412m2_device::dac_timer_w)); // timer frequency
map(0x19, 0x19).nopw(); // 2 written at POST
map(0x51, 0x52).w(FUNC(nb1412m2_device::dac_address_w)); // start address
@@ -158,6 +156,7 @@ void nb1412m2_device::device_start()
save_item(NAME(m_dac_playback));
save_item(NAME(m_dac_frequency));
save_item(NAME(m_const90));
+ save_item(NAME(m_timer_rate));
m_timer = timer_alloc(TIMER_MAIN);
m_timer->adjust(attotime::never);
@@ -179,9 +178,9 @@ void nb1412m2_device::device_reset()
m_rom_op = 0;
m_const90 = 0x18; // fixes coin sample if inserted at first title screen
m_dac_current_address = m_dac_start_address = 0;
- m_dac_frequency = 4000;
m_timer_reg = false;
m_dac_playback = false;
+ dac_timer_w(0xd0);
m_dac_timer->adjust(attotime::never);
}
@@ -290,8 +289,10 @@ void nb1412m2_device::timer_w(uint8_t data)
if(data != 1)
logerror("nb1412m2: timer_w with data == %02x\n",data);
- // TODO: timing of this, related to m_const90?
- m_timer->adjust(attotime::from_hz(960));
+ // The DAC frequency and timer clock are linked.
+ // When the DAC clock changes, sound driver sets wait loop count ($C010)
+ // in the range of 2 to 4 in order to keep the tempo of BGM even if clock changed.
+ m_timer->adjust(attotime::from_hz(double(clock()) / (256 * 35) * m_timer_rate));
}
void nb1412m2_device::timer_ack_w(uint8_t data)
@@ -314,13 +315,22 @@ void nb1412m2_device::dac_address_w(offs_t offset, uint8_t data)
}
}
+void nb1412m2_device::dac_control_w(uint8_t data)
+{
+ if (data == 0)
+ {
+ // Mighty Guy is uses this to stop psycho gun sound.
+ m_dac_playback = false;
+ }
+}
+
// seems directly correlated to the DAC timer frequency
// 0xd0 - 0xe0 - 0xf0 are the settings used
void nb1412m2_device::dac_timer_w(uint8_t data)
{
-// popmessage("%02x",data);
- // TODO: unknown algo, 0xe0*18 gives 4032 Hz which seems close enough for sample 36
- m_dac_frequency = data*18;
+ // TODO: Algorithm is unknown
+ m_timer_rate = ((data & 0x30) >> 4) + 1;
+ m_dac_frequency = double(clock()) / (256 * 12) * m_timer_rate;
}
// controls music tempo
diff --git a/src/mame/machine/nb1412m2.h b/src/mame/machine/nb1412m2.h
index 67f6f690f47..afdbc30a8f4 100644
--- a/src/mame/machine/nb1412m2.h
+++ b/src/mame/machine/nb1412m2.h
@@ -47,7 +47,8 @@ private:
uint16_t m_rom_address;
uint16_t m_adj_address;
uint16_t m_dac_start_address, m_dac_current_address;
- int m_dac_frequency;
+ double m_dac_frequency;
+ uint8_t m_timer_rate;
uint8_t m_rom_op;
uint8_t m_const90;
bool m_timer_reg;
@@ -72,6 +73,7 @@ private:
uint8_t const90_r();
void const90_w(uint8_t data);
void dac_address_w(offs_t offset, uint8_t data);
+ void dac_control_w(uint8_t data);
void dac_timer_w(uint8_t data);
};