Simplest way to integrate an nsf to your game code.

Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music.

Moderator: Moderators

Tompis1995
Posts: 34
Joined: Fri Feb 22, 2019 10:05 am

Simplest way to integrate an nsf to your game code.

Post by Tompis1995 »

Hello again. It's been a while since I last visited this forum. I was wondering if there is any simple way of adding sound to game codes. I've already covered this topic with the DPCMs, but this time it's for the pulse channels. Can anyone provide me a tutorial revolving around this? Thanks! I'm still a huge dummy noob though.
Joe
Posts: 650
Joined: Mon Apr 01, 2013 11:17 pm

Re: Simplest way to integrate an nsf to your game code.

Post by Joe »

You still can't integrate an NSF into another ROM.

But tools that can generate NSFs usually also provide the data in another format that can be integrated into your game. How are you getting your NSF?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Simplest way to integrate an nsf to your game code.

Post by tokumaru »

NSFs are complete NES programs, containing all the song data as well as the code to play it. While it's generally possible to put this inside your own NES program, this is not very practical because you have little control over where the data and code are placed, and absolutely zero control over what RAM addresses are used by the playback code, which can make the mapping of your own variables much more difficult and error-prone.

The more standard way of adding songs to an NES program is to include the data and the playback engine separately, instead of as a single blob, and configure certain aspects about the engine, such as where its variables go in RAM.

Most tools used to compose NES music can provide you with the separate data and engine, and there are also engines with tools that will convert data from other formats into their own.

The bottom line is that it's much better to include a configurable engine and the sound data separately than an NSF.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Simplest way to integrate an nsf to your game code.

Post by Dwedit »

If your program is really really simple, you can take an NSF file and write your game so that it doesn't overlap any ROM or RAM addresses, and you call the init and playback routines properly.

Only really suitable for very simple demo programs though. You generally don't want to do this, as it is very restrictive. But it does work.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
Individualised
Posts: 310
Joined: Mon Sep 05, 2022 6:46 am

Re: Simplest way to integrate an nsf to your game code.

Post by Individualised »

What are you using to create NSF files? As said already NSF files are complete ROMs and not just APU playback data, but depending on what program you're using to create NSFs you might be able to export as another format and integrate a compatible sound driver into your game.
Tompis1995
Posts: 34
Joined: Fri Feb 22, 2019 10:05 am

Re: Simplest way to integrate an nsf to your game code.

Post by Tompis1995 »

Alright, what I've done was follow the instructions to include the famitone2 library into my project using "incbin famitone2.s" But for some reason after compiling, I get an error saying that a variable belonging to famitone2.s is undefined. It seems as though the compiler is only looking for variables in the project file instead of also searching through the files included through incbin. How on earth can I make the compiler find variables that only exist in nested files?
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: Simplest way to integrate an nsf to your game code.

Post by Fiskbit »

incbin is for including raw binary files, ie embedding the data directly into the resulting program. You want to be using include, which is for including source files such that they actually get assembled. I don't know if that's your only problem, but I'd start there.
Joe
Posts: 650
Joined: Mon Apr 01, 2013 11:17 pm

Re: Simplest way to integrate an nsf to your game code.

Post by Joe »

Since "famitone2.s" is the CA65 version, you might instead want to build it as a separate object file and then link it with the rest of your code using LD65.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Simplest way to integrate an nsf to your game code.

Post by tokumaru »

Joe wrote: Sat Nov 12, 2022 4:25 pm Since "famitone2.s" is the CA65 version, you might instead want to build it as a separate object file and then link it with the rest of your code using LD65.
This doesn't make things any simpler for someone who's clearly a beginner, though.
Tompis1995
Posts: 34
Joined: Fri Feb 22, 2019 10:05 am

Re: Simplest way to integrate an nsf to your game code.

Post by Tompis1995 »

Alright, the .include method does eliminate the error, however, the rom isn't playing any sound. Can someone provide me a tutorial related to my issue?
Tompis1995
Posts: 34
Joined: Fri Feb 22, 2019 10:05 am

Re: Simplest way to integrate an nsf to your game code.

Post by Tompis1995 »

And in case for those seeking context of my situation, I'm trying to get the rom to emulate the sound made by the Press Your Luck board. I'll provide some attachments for your evaluation. If you need me to include famitone2.s, let me know.
Attachments
PYL_Board.s
(897 Bytes) Downloaded 32 times
pyl.asm
(10.72 KiB) Downloaded 31 times
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Simplest way to integrate an nsf to your game code.

Post by tokumaru »

I see you're initializing Famitone, but you still need to tell it to actually play the song. For this you need to put the number of the song to play in the accumulator and call FamiToneMusicPlay.
Tompis1995
Posts: 34
Joined: Fri Feb 22, 2019 10:05 am

Re: Simplest way to integrate an nsf to your game code.

Post by Tompis1995 »

I started following the Nerdy Nights tutorial on sounds and wrote my own sound_engine.asm with a couple of snippets copied from the 'skeleton' folder. However, after I was confident I had written all the necessary data, when I launched the "game" in an emulator, no sound is made. Why is that?

My main program of playing with sounds:
soundGeneratorPlayground.asm
(2.38 KiB) Downloaded 35 times
My edited version of the sound engine:
sound_engine.asm
(2.65 KiB) Downloaded 36 times
The zip file I extracted the original asm files can be found here: https://nerdy-nights.nes.science/#audio_tutorial-1

I'm also using ca65 to compile my stuff as opposed to NESASM.
User avatar
Memblers
Site Admin
Posts: 4044
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Simplest way to integrate an nsf to your game code.

Post by Memblers »

Tompis1995 wrote: Mon Nov 14, 2022 6:42 pm However, after I was confident I had written all the necessary data, when I launched the "game" in an emulator, no sound is made. Why is that?
My main program of playing with sounds: soundGeneratorPlayground.asm
NMI needs to be enabled with register $2000, the Vblank code looks like it's not running. Also, $4015 will need to be set at some poit, I see it commented out.
Tompis1995
Posts: 34
Joined: Fri Feb 22, 2019 10:05 am

Re: Simplest way to integrate an nsf to your game code.

Post by Tompis1995 »

Now I started using the FamiStudio engine and after even more editing, I'm left with this baffling error every time I compile:

Code: Select all

ld65: Warning: Cannot evaluate assertion in module 'famistudio_ca65.s', line 4376
ld65: Error: Missing memory area assignment for segment 'RAM'
Even after including a 'RAM' segment into my main program, it still throws me this error. I have no clue how to comprehend the meaning of the first error message let alone the last one. Can someone help me explain what is going on and how to resolve this issue????
Post Reply