APU behavior (Eliminator Boat Duel)

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
Eugene.S
Posts: 291
Joined: Sat Apr 18, 2009 4:36 am
Location: Russia (UTC+3)
Contact:

APU behavior (Eliminator Boat Duel)

Post by Eugene.S » Mon Jan 07, 2019 1:34 pm

Hi nesdev.

"Eliminator Boat Duel (USA).nes" must have buzz sound on power-on, you can hear it on some emulators
(nintendulator, nestopia, fceux, rocknes for example)
I remember it was present on real hardware but need to re-test it again on famicom some day.

Strange, but most of top-accurate NES emulators (mesen, punes, bizhawk) play silence at startup.
Is it bug?

Sour
Posts: 736
Joined: Sun Feb 07, 2016 6:16 pm

Re: APU behavior (Eliminator Boat Duel)

Post by Sour » Mon Jan 07, 2019 5:27 pm

I think I've figured this one out. The game enables the DMC channel without ever writing to $4012/$4013 to initialize those registers. Then it keeps writing to $4015 (once per frame) with the DMC enabled flag set. According to the Wiki, this restarts the DMC sample if it has stopped playing ("If the DMC bit is set, the DMC sample will be restarted only if its bytes remaining is 0."), which essentially means the game ends up reading random data between $C000-$FFFF and playing it as a DMC sample.

Mesen initializes the sample address and length with a 0 (which is probably impossible, hardware-wise), which means nothing gets played at all, even though $4015 is written to with the DMC flag enabled. If I initialize those values with $C000 and 1 (which are their minimum respective values normally), a buzzing sound can be heard and never stops throughout the game, because the game keeps writing to the $4015 register with the DMC enabled flag set.

I suppose the power on values could potentially be anything (or even random), though given that the CPU powers on with specific values for registers and the like, it's likely that there is a specific value for these. Would be interesting to see if the register values are affected by a reset, too.

User avatar
Eugene.S
Posts: 291
Joined: Sat Apr 18, 2009 4:36 am
Location: Russia (UTC+3)
Contact:

Re: APU behavior (Eliminator Boat Duel)

Post by Eugene.S » Mon Jan 07, 2019 5:34 pm

The game enables the DMC channel without ever writing to $4012/$4013 to initialize those registers. Then it keeps writing to $4015 (once per frame) with the DMC enabled flag set.
If I initialize those values with $C000 and 1 (which are their minimum respective values normally), a buzzing sound can be heard and never stops throughout the game, because the game keeps writing to the $4015 register with the DMC enabled flag set.
It's game abnormal behavior, yes. Anyway i will test it on real hardware.

lidnariq
Posts: 8690
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: APU behavior (Eliminator Boat Duel)

Post by lidnariq » Mon Jan 07, 2019 5:45 pm

Looking in Visual2A03...

/RESET clears the DPCM pointer "pcm_a0" through "pcm_a14" ... but...
Restarting DPCM by writing to $4015 with the bit DPCM bit set (i.e. node 11092) reloads pcm_a6 through pcm_a13 from pcm_sa0 through pcm_sa7 (and clears pcm_a0 through pcm_a5 and sets pcm_a14)

The value in pcm_saX is neither set nor cleared on /RESET, and the storage device - two inverters and a transmission gate - looks like it should come out of cold boot usually low.
(Specifically: both pcm_sa0 and pcm_/sa0 have the same geometry of pullup, but pcm_sa0 is larger and so its charge time should be slower, so pcm_/sa0 should reach logic high earlier).

edit: similarly, /RESET also clears the DPCM "bytes remaining" "pcm_lc0" through "pcm_lc11", but it also is reloaded from pcm_l7 through pcm_l0, which is also not explicitly set during reset, and also should tend towards 0 on cold boot

So if I'm reading this correctly:
DPCM halted and address set to $8000 on all resets, but this address can't actually matter
DPCM start address not initialized in hardware, but probably $8000 on cold boot, and definitely unchanged on warm boot.
edit: DPCM length also not initialized in hardware, and probably 0 (meaning "1 byte") on cold boot, and unchanged on warm boot
Last edited by lidnariq on Mon Jan 07, 2019 6:02 pm, edited 2 times in total.

User avatar
rainwarrior
Posts: 7636
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: APU behavior (Eliminator Boat Duel)

Post by rainwarrior » Mon Jan 07, 2019 5:46 pm

Running the game on my PowerPak / NES I hear the buzz constantly, at the title screen and during most of the game (except when paused).

Though because it's 60Hz, I probably would have assumed it was just crosstalk from the video signal if playing on hardware... but obviously that doesn't happen in an emulator.

Reminded slightly of the codemasters buzz.

Sour
Posts: 736
Joined: Sun Feb 07, 2016 6:16 pm

Re: APU behavior (Eliminator Boat Duel)

Post by Sour » Mon Jan 07, 2019 7:13 pm

lidnariq wrote:DPCM start address not initialized in hardware, but probably $8000 on cold boot, and definitely unchanged on warm boot.
edit: DPCM length also not initialized in hardware, and probably 0 (meaning "1 byte") on cold boot, and unchanged on warm boot
I'm assuming you meant $C000 rather than $8000? (Since the DMC can only load from $C000-$FFFF?)

I've attached a very basic test ROM that should buzz on power on (Disclaimer: I still suck at 6502 assembly)
On FCEUX/Nestopia/VirtuaNES it buzzes, on Mesen 0.9.7 and Bizhawk, it doesn't.

Only byte $C000 is set in memory (to a value that sounded relatively loud from my testing), everything else in the $C000-$FFFF range is $00 except the vector bytes. Assuming it buzzes on hardware, it should confirm the power on state to be $C000.

Edit: Also, this may not work properly on a powerpak/etc since they may initialize the registers to something else?
Attachments
DmcPowerOnTest.zip
(31.22 KiB) Downloaded 264 times

lidnariq
Posts: 8690
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: APU behavior (Eliminator Boat Duel)

Post by lidnariq » Mon Jan 07, 2019 7:22 pm

Sour wrote:I'm assuming you meant $C000 rather than $8000? (Since the DMC can only load from $C000-$FFFF?)
Nope! I definitely do mean $8000.

You may recall that DPCM that starts at $FFC0 and extends past $FFFF will overflow to $8000...

For whatever reason, it's a 15-bit counter – compare Visual2A03 transistor "t16851", which connects "pcm_+a14" to the address bus multiplexer, vs transistor "t16954" which instead just pulls a15 high.

The thing that initialized pcm_a14 is transistor "t16835" which always pulls the signal high.

Sour
Posts: 736
Joined: Sun Feb 07, 2016 6:16 pm

Re: APU behavior (Eliminator Boat Duel)

Post by Sour » Mon Jan 07, 2019 7:40 pm

lidnariq wrote:Nope! I definitely do mean $8000.

You may recall that DPCM that starts at $FFC0 and extends past $FFFF will overflow to $8000...
I don't think I've ever been aware of this. And actually Mesen's code currently wraps to $0000 after $FFFF, as far as I can tell, whoops.

Sour
Posts: 736
Joined: Sun Feb 07, 2016 6:16 pm

Re: APU behavior (Eliminator Boat Duel)

Post by Sour » Mon Jan 07, 2019 8:55 pm

Alright, with that in mind, let's try this again!

Here are 2 tests, both of them have all their code/data in the $F000-FFFF range.

The $8000 version sets $8000 to $87, and everything else is $00.
The $C000 version sets $C000 to $87, and everything else is $00.

I'd expect the $8000 version to buzz, while the $C000 version should be silent. None of the emulators I tested buzz on the $8000 version at the moment.

Eliminator Boat Duel seems to have the value $4C at both $8000 and $C000, so it would sound the exact same in both scenarios (which means emulators that currently emulate the buzz properly might only be getting it right by luck)
Attachments
DmcPowerOnTest_v2.zip
(33.42 KiB) Downloaded 260 times

User avatar
Eugene.S
Posts: 291
Joined: Sat Apr 18, 2009 4:36 am
Location: Russia (UTC+3)
Contact:

Re: APU behavior (Eliminator Boat Duel)

Post by Eugene.S » Tue Jan 08, 2019 1:44 am

FCAV test record is here

Eliminator Boat Duel is buzzing
$C000 is buzzing
$8000 is silent (sometimes after restart it have graphical garbage)

Nintendulator, nestopia, fceux, and even old nnnesterj and virtuanes
pass this test same way as hardware,
but rocknes have silence on both (but buzzing on boat duel)

Mesen, puNES, BizHawk(NESHawk) and MyNES have silence on tests and on Boat Duel too.
Last edited by Eugene.S on Tue Jan 08, 2019 2:41 am, edited 2 times in total.

lidnariq
Posts: 8690
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: APU behavior (Eliminator Boat Duel)

Post by lidnariq » Tue Jan 08, 2019 2:04 am

... <facepalm> Right, made a mistake. I even explained why but didn't finish thinking it through ... it's specifically the pcm_sa0 through pcm_sa7 latches that're uninitialized, and when DPCM is restarted by writing to $4015, pcm_a14 is initialized high there.

User avatar
Eugene.S
Posts: 291
Joined: Sat Apr 18, 2009 4:36 am
Location: Russia (UTC+3)
Contact:

Re: APU behavior (Eliminator Boat Duel)

Post by Eugene.S » Tue Jan 08, 2019 2:57 am

So, i guess this title will confusing other emu developers
Attachments
DmcPowerOn_v2_8000.png
DmcPowerOn_v2_8000.png (3.41 KiB) Viewed 7985 times

Fiskbit
Posts: 75
Joined: Sat Nov 18, 2017 9:15 pm

Re: APU behavior (Eliminator Boat Duel)

Post by Fiskbit » Tue Jan 08, 2019 4:18 am

I did some testing with my own test ROMs on Everdrive and suspect that its firmware writes to these registers (unless I was doing something wrong, setting the address in one ROM and switching to another did not seem to preserve it), so I can't say much about the power-on values, but it does appear that registers are indeed unchanged by reset. My tests modify the length because they play actual samples; sour's tests are probably more useful because they leave length alone, so I don't intend to post mine unless someone wants them.

User avatar
Zepper
Formerly Fx3
Posts: 3190
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: APU behavior (Eliminator Boat Duel)

Post by Zepper » Tue Jan 08, 2019 6:23 am

So, what's the correct setting for DMC powerup/reset? Address is set to $8000... or would it be $C000?
In my emulator (current beta), I could "fix" the buzzing by doing the following:

1. There's a frequency table.

Code: Select all

static const int freq_table[0x10] = { 
  0x1AC, 0x17C, 0x154, 0x140, 0x11E, 0x0FE, 0x0E2, 0x0D6,
  0x0BE, 0x0A0, 0x08E, 0x080, 0x06A, 0x054, 0x048, 0x036
};
2. Once DMC frequency_counter expires, frequency_counter = freq_table[$4010 AND 15];

3. So... the buzzing sound is hearded if I do frequency_counter = freq_table[0] on reset/powerup, plus setting dmc_length = 1.

4. DMC address at $8000 on powerup/reset does NOT output the buzzing sound.

Sour
Posts: 736
Joined: Sun Feb 07, 2016 6:16 pm

Re: APU behavior (Eliminator Boat Duel)

Post by Sour » Tue Jan 08, 2019 6:37 am

Eugene.S wrote:So, i guess this title will confusing other emu developers
I'll post a final "v3" with updated text to say which test should be silent or playing a sound when I get a chance (e.g after work). Thanks for running the tests, by the way!
Zepper wrote:So, what's the correct setting for DMC powerup/reset? Address is set to $8000... or would it be $C000?
Based on Eugene's results, the sample address should be initialized to $C000 and length to 1 byte, which should cause a buzzing on the C000 test.

Post Reply