Question about a negative overflow in APU pulse sweep

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
TaoTao
Posts: 2
Joined: Wed Feb 29, 2012 3:33 am

Question about a negative overflow in APU pulse sweep

Post by TaoTao »

According to Wiki, when the sweep of APU pulse channel 1 is configured that negate flag is true and shift count is zero (that is, $08 is written to $4001), a negative overflow seems to occur in target period calculation:

Code: Select all

target_period = current_period - current_period - 1
In this case, what is the exact value of target period? Is it greater than $7FF? Or saturated to zero?
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Question about a negative overflow in APU pulse sweep

Post by rainwarrior »

I'm pretty certain it just clamps to 0 (which also silences the channel).

This is what NSFPlay does.

I'm not sure I've ever explicitly tested this behaviour, but I think failing to clamp would mean that the square with negate and shift 0 would constantly be changing pitch by 1 and never stop, which would cause it to sweep across the whole frequency range over and over as it overflows, which is not something I've ever observed.
TaoTao
Posts: 2
Joined: Wed Feb 29, 2012 3:33 am

Re: Question about a negative overflow in APU pulse sweep

Post by TaoTao »

rainwarrior, Thank you for a convincing explanation!
Indeed, such a forever sweep seems to be unlikely.

I read some NSFPlay code and it seems very nice. I will refer it when I have trouble.
notyourdad
Posts: 16
Joined: Sun Mar 12, 2023 5:49 am

Re: Question about a negative overflow in APU pulse sweep

Post by notyourdad »

Aha! This is the same issue I ran into with my FPGA project announcement that resulted in a great big faceplant. A bunch of games were missing a pulse channel in my demo video #embarrassing. In that thread, I recommended a Wiki update for the APU Pulse document to capture this detail.
User avatar
Anes
Posts: 702
Joined: Tue Dec 21, 2004 8:35 pm
Location: Mendoza, Argentina

Re: Question about a negative overflow in APU pulse sweep

Post by Anes »

I had troubles not implementing the "negative" in the second channel.
1943 overflowed and the game sound scretched. So its a thing that must be done.
ANes
Post Reply