"APU basics": register initialization question

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

lidnariq
Site Admin
Posts: 11623
Joined: Sun Apr 13, 2008 11:12 am

Re: "APU basics": register initialization question

Post by lidnariq »

furrykef wrote:There might be some tutorial (either now or in the future) where DMA is done once during initialization and then ignored, which would make sense for a program without sprites. If that DMA is done before initializing sound, the poor user might waste hours trying to find out why he's getting garbage on the screen when he runs his program. And for what? To save two bytes in the sound initializer?
When the PPU first powers up, OAM contains garbage in the first place. Garbage from a nonsense DMA isn't going to be meaningfully differently deleterious...

That said, I should write that OAM cold-boot DRAM test.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: the universe
Contact:

Re: "APU basics": register initialization question

Post by thefox »

furrykef wrote:
thefox wrote:I bet this is why the comments about the purpose of the initialization values were removed, and also why it doesn't care about triggering a most likely harmless OAM DMA.
This is a dangerous attitude to have. For one thing, if you're going to put up a message saying not to modify the code at all, it had better be good code. It wasn't.

Second, you're making a lot of assumptions in calling the OAM DMA "most likely harmless". Sure, it's harmless if another DMA is done right afterward, but there's no reason to presume so. There might be some tutorial (either now or in the future) where DMA is done once during initialization and then ignored, which would make sense for a program without sprites. If that DMA is done before initializing sound, the poor user might waste hours trying to find out why he's getting garbage on the screen when he runs his program. And for what? To save two bytes in the sound initializer?
I'm not really arguing whether it's good or bad, just trying to provide my guess at why those decisions were made, since many people in the thread seemed to be misunderstanding the purpose of that page. (You're going to have to ask blargg if you want the real reasons, he created the page.)

BTW, doing OAM DMA once in initialization is bad practice. It's very easy to accidentally run too much code after the DMA before enabling rendering, causing it to decay and to not have a well-defined state after all. If you're not using sprites, you can turn off their rendering in $2001 and not care about the state of OAM.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
rainwarrior
Posts: 8758
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: "APU basics": register initialization question

Post by rainwarrior »

thefox wrote:I'm not really arguing whether it's good or bad
IMO the overall premise of this page is good. A fairly minimal set of steps showing how to make the APU play a sound on 4 of its channels. It's a nice little tutorial, similar to the first few programs I ever wrote to teach myself how to use the APU.

I have a laundry list of little nitpicks with it, which I left on the wiki (sorry to fragment the discussion), but I think in general the page is worth keeping and maintaining.
User avatar
B00daW
Posts: 586
Joined: Thu Jan 03, 2008 1:48 pm

Re: "APU basics": register initialization question

Post by B00daW »

(Move to "NES Music", please. :) )
User avatar
rainwarrior
Posts: 8758
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: "APU basics": register initialization question

Post by rainwarrior »

There's no music in this thread. The questions are about programming.

Is it policy that anything related to sound program belongs in "NES Music" now? I don't think it's been this way in the past... most APU programming stuff seems to be under NESdev.
User avatar
B00daW
Posts: 586
Joined: Thu Jan 03, 2008 1:48 pm

Re: "APU basics": register initialization question

Post by B00daW »

rainwarrior wrote:There's no music in this thread. The questions are about programming.

Is it policy that anything related to sound program belongs in "NES Music" now? I don't think it's been this way in the past... most APU programming stuff seems to be under NESdev.
"Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music."
Revenant
Posts: 463
Joined: Sat Apr 25, 2015 1:47 pm
Location: FL

Re: "APU basics": register initialization question

Post by Revenant »

I think most people would assume that means "anything else related to creating NES music", not how to correctly poke some registers in an assembly program.
User avatar
B00daW
Posts: 586
Joined: Thu Jan 03, 2008 1:48 pm

Re: "APU basics": register initialization question

Post by B00daW »

Pretty sure poking around at sound registers to make output is creating music/art; regardless of standard convention. :)
furrykef
Posts: 35
Joined: Fri Mar 02, 2012 11:10 pm

Re: "APU basics": register initialization question

Post by furrykef »

I did think of a reason to write to the regs in ascending order instead of descending: I forgot that the registers $4003, $4007, etc. can act as triggers, so you might not want to write to them until after writing to the other registers for that channel. Dunno if that affects how this particular code works or not.
User avatar
Bregalad
Posts: 8104
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: "APU basics": register initialization question

Post by Bregalad »

B00daW wrote:(Move to "NES Music", please. :) )
Please don't. The discussion here has nothing to do with music.
User avatar
rainwarrior
Posts: 8758
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: "APU basics": register initialization question

Post by rainwarrior »

furrykef wrote:I did think of a reason to write to the regs in ascending order instead of descending: I forgot that the registers $4003, $4007, etc. can act as triggers, so you might not want to write to them until after writing to the other registers for that channel. Dunno if that affects how this particular code works or not.
It doesn't really matter for the example, which doesn't use the triggered features, but I agree (I made the same suggestion on the wiki talk page). Those registers are canonically the "start a note" register, by design.
User avatar
B00daW
Posts: 586
Joined: Thu Jan 03, 2008 1:48 pm

Re: "APU basics": register initialization question

Post by B00daW »

Bregalad wrote:
B00daW wrote:(Move to "NES Music", please. :) )
Please don't. The discussion here has nothing to do with music.
OK. Well, you used the word "nothing". Let's either reset 2a0x code without init code or play music code without clear commands during a reset.

How much of "nothing" is involved with initialization and clearing bits of APU code?

Secondary question, if PPU and/or APU code related to their respective "territories" is an instigated topic within "NESdev" of the forums, when is it not appropriate to move to respective forums of the questioned topic?
User avatar
rainwarrior
Posts: 8758
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: "APU basics": register initialization question

Post by rainwarrior »

B00daW wrote:Let's either reset 2a0x code without init code or play music code without clear commands during a reset.
Lots of people make NES music without writing any code at all (and those people don't post in the Dev forum).

Programming stuff mostly go in the Dev forum. The resulting art and music mostly goes in the Graphics and Music forums.

There's a ton of PPU programming threads in the Dev forum, hardly anybody posts that kind of thing in the Graphics forum. The more technical Graphics forum posts are usually more like "what is possible on the NES", not "here's how reads from $2007 are buffered".

The Music forums are mostly music people have made, album releases, NSF rips, tools to make music, etc. Hardly anybody posts there about programming the APU.

People post against the trend in either forum now and then, but this isn't one of those. I agree that APU programming is related to music, but it's still more appropriate for the Dev forums. Ideally instead of separate forums I wish we'd just have category tags, so it could exist happily with both tags, but that just isn't the world we live in.
User avatar
za909
Posts: 264
Joined: Fri Jan 24, 2014 9:05 am
Location: Mijn hart woont al in Nederland

Re: "APU basics": register initialization question

Post by za909 »

Based on a quick look at that page I'm extremely happy that when I started out I only ever used the APU reference to do what I wanted... part of the truth was that I had already familiarized myself with most of the APU features through Famitracker so it all made sense to me.
Post Reply