Simplest way to integrate an nsf to your game code.
Moderator: Moderators
-
- Posts: 34
- Joined: Fri Feb 22, 2019 10:05 am
Simplest way to integrate an nsf to your game code.
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.
Re: Simplest way to integrate an nsf to your game code.
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?
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?
Re: Simplest way to integrate an nsf to your game code.
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.
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.
Re: Simplest way to integrate an nsf to your game code.
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.
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!
- Individualised
- Posts: 310
- Joined: Mon Sep 05, 2022 6:46 am
Re: Simplest way to integrate an nsf to your game code.
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.
-
- Posts: 34
- Joined: Fri Feb 22, 2019 10:05 am
Re: Simplest way to integrate an nsf to your game code.
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?
Re: Simplest way to integrate an nsf to your game code.
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.
Re: Simplest way to integrate an nsf to your game code.
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.
-
- Posts: 34
- Joined: Fri Feb 22, 2019 10:05 am
Re: Simplest way to integrate an nsf to your game code.
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?
-
- Posts: 34
- Joined: Fri Feb 22, 2019 10:05 am
Re: Simplest way to integrate an nsf to your game code.
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
Re: Simplest way to integrate an nsf to your game code.
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.
-
- Posts: 34
- Joined: Fri Feb 22, 2019 10:05 am
Re: Simplest way to integrate an nsf to your game code.
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: My edited version of the sound engine: 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.
My main program of playing with sounds: My edited version of the sound engine: 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.
Re: Simplest way to integrate an nsf to your game code.
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 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
-
- Posts: 34
- Joined: Fri Feb 22, 2019 10:05 am
Re: Simplest way to integrate an nsf to your game code.
Now I started using the FamiStudio engine and after even more editing, I'm left with this baffling error every time I compile:
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????
Code: Select all
ld65: Warning: Cannot evaluate assertion in module 'famistudio_ca65.s', line 4376
ld65: Error: Missing memory area assignment for segment 'RAM'