I created a song in Famitracker that I plan to put in a new game I'm making. How would I put it in a game that I'm making in 6502 asm? I tried generating a .asm file with the "Create .nsf" dialog, but I'm unsure how to play it. I will have sound effects playing with the music, as well.
It depends on which effects and instrument features your piece uses. Two publicly available music engines that can be used with music composed in FamiTracker are
Pently and
FamiTone2. Neither supports all effects and instrument features.
But, you forget, Shiru made a full famitracker driver that is compatible with famitone2. And, it is what I'm using for my Ninja game.
It's also complicated, and cc65. And needs lots of ROM space for music data.
I'm not using any effects except Cxx (halt song), and my instruments only have volume changes. Thanks for pointing me to Famitone2, I might use that. Is that compatible with NESASM3?
JWinslow23 wrote:
Is that compatible with NESASM3?
Why don't you download it and check it out?
As dougeff already said: Shiru made two versions of it.
The regular FamiTone2 v1.15 is the one that he created as a minimalistic sound driver for NES development.
And because he got frustrated by people who complained that certain things don't work in FamiTone, he created neslib + FamiTracker player which uses the original FamiTone only for sound effects while the music is done with the native FamiTracker driver:
Quote:
Since release of FamiTone I was getting complaints on how restricted it is, and
how missing features not allowing to create good music with it. It gets as far
as people now trying to expand the engine to support more FamiTracker features,
for some reason - rather pointless to me, as the very idea of FamiTone was to be
that restricted, the design was never intended to be expandable, and it would be
easier to just write another engine from scratch.
So, it's your choice which one you want to use.
With neslib + FamiTracker player, you can do everything that FamiTracker can do. But it will probably require a lot of ROM space and I assume calling the functions would also require a lot of the precious CPU time (which, unlike ROM space, cannot be added with mappers).
For my game, I used the regular FamiTone, i.e. the limited, but small one.
I don't understand the problem many people have. I myself don't know much about making music. But I would say my composer did a pretty neat soundtrack, even with FamiTone's restrictions:
https://iyamwhatiyam.bandcamp.com/releases
I'm having a problem in the first step. When I'm using the text2data tool that comes with Famitone, it always crashes. There is no error message, it just freezes for a second, and then my computer says "text2data.exe has stopped working". I'm on Windows 10, and the .txt file FamiTracker generates is attached. How do I fix this?
What happens when you just call the program without any parameters? Does the error appear as well?
If yes, you might have to install the Visual C++ Runtime (version 2008 or later) first.
Edit: The problem happens on my PC as well, but only with your FamiTracker file.
Did you use the regular FamiTracker or that beta version?
I assume you have to use FamiTracker 0.4.6.
Without any parameters, it just gives me usage information.
I added some text to my previous post.
Alright, I see now: Your file is created from FamiTracker 0.4.2. I'd suggest to download the latest version (0.4.6):
www.famitracker.com/downloads.php
I did get FamiTracker v0.4.6. That's what it says in the "About FamiTracker" information. I also have the latest version of Famitone.
I'm confused. :\
Here is my actual FamiTracker project, if it's something to do with that. (It has two songs: the main theme, and a "flap" sound-effect.)
O.k., looks like the problem is with your FTM file somehow since it has exactly the same symptoms on my PC.
In the past, we've had this as well, that some dirty stuff was somewhere inside the binary file that was also put into the text file and made it semi-invalid.
My suggestion:
Open a clean new file (with the latest FamiTracker version).
Open the current file in another FamiTracker instance.
Put everything from the dirty file to the clean file via copy & paste.
And then save the clean file.
Whatever dirty stuff is in the old file should be gone. (You can do a file compare of the text export from the new and the old file to see where they differ.)
Unrelated hint, but this has nothing to do with the error: Sound effects have to be created with nsf2data and therefore go into a separate file.
Unfortunately, sound effects in FamiTone cannot use an infinite loop. If you want an infinite sound effect, you either have to time the sound effect call in code or you have to do it as a song after all. But doing it as a song means that you cannot have another background song while the effect is played.
DRW wrote:
Unrelated hint, but this has nothing to do with the error: Sound effects have to be created with nsf2data and therefore go into a separate file.
Unfortunately, sound effects in FamiTone cannot use an infinite loop. If you want an infinite sound effect, you either have to time the sound effect call in code or you have to do it as a song after all. But doing it as a song means that you cannot have another background song while the effect is played.
I do not want an infinite loop. I actually made it stop with Cxx, but apparently Famitone doesn't support that. What effect would do this?
Also, I got text2data working now, thanks!
I had no problems. (note, I removed the 2nd song before exporting from 0.4.6).
(leaving it on crashes text2data for some reason).
dougeff wrote:
I had no problems. (note, I removed the 2nd song before exporting from 0.4.6)
Deleting a song doesn't solve the issue, it just circumvents it. You might still run into the problem once you want to use the sound effect.
JWinslow23 wrote:
I actually made it stop with Cxx, but apparently Famitone doesn't support that. What effect would do this?
Oh, right: If you want a song to stop in FamiTone, you have to create a silent pattern and make it loop itself.
If you want a sound effect to stop, you can use Cxx, but sound effects are created from an NSF export with nsf2data.
text2data works without that second "song" (sound effect). But then what's the deal with sound effects? Would they be in a different Famitracker project?
Music: Works with text export and text2data.
Sound effects: Work with NSF export and nsf2data.
Sound effects can basically use any effect available in FamiTracker, including Cxx. They don't have the limitations of songs.
In a game, you would put all the music in one FamiTracker file and all the sound effects into another FamiTracker file since one has to be exported as txt and the other as nsf.
That makes sense, I guess. Alright, I'll do those separately. Thank you!
EDIT: Well, now that the music is in the game, I'm not exactly sure what to do. The compiled .nes file not only doesn't play music, but my character just starts in the middle of the screen and I can't control it. The screen is scrolling, though.
Code attached. What am I doing wrong?
your include statements are outside of the bank statements / org statements, so they weren't included in the ROM. It probably started counting from $0000. So this statement...
JSR FamiToneUpdate
probably sent the program somewhere between $0000 and $7fff, where there is no code. It probably saw a BRK (00) and jumped to the IRQ/Break code, which you have none defined (except 0000), anyway infinitely finding BRK and jumping to address $0000 at that point. Occasionally, an NMI would fire, and it would jump to the start of the NMI code, do some auto-scrolling, and then get lost again once it reaches JSR FamiToneUpdate.
BTW, I don't use NESASM, but I don't think you are supposed to put colons on = statements. I pulled this from a source file I found...
sprite = $0200
It was not indented. But, definitely, no colon.
Well, it was the only way it could compile, is if colons were put in front of the define statements.
Also, now I have put both includes at the beginning of $C000, and the music works! Only one thing: how do you properly check whether the game is running on a PAL or NTSC system? I'm checking with some code I saw in FamiTone's demo, but it doesn't seem to be correcting the pitch right. Any code I can put in to properly check the region?
Detect TV system then store the value it produces. If it doesn't appear to be correcting pitch correctly, debug it to see what value it is producing.
I've gotten that to work, thank you!
The only thing is, now (not sure if this has to do with the music, or just faulty scroll update code), for one frame after the walrus falls past the bottom of the screen, the background gets shifted down weirdly, and then goes back to normal. Is there a JSR UpdateScroll I'm missing?
Code attached. walrush_music.asm and famitone2.asm are unchanged.
Just post the .nes file. Don't make me have to try to assemble it with only half the source files.
A lot of debugging is stepping slowly through the code in a debugger, watching for things happening outside of v-blank (writes to PPU). Learn that. You will be doing it 100+ times during development.
Sorry, I'll upload the .nes file.
EDIT: Never mind, I was able to fix it myself through trial and error. Still, thanks!
There is 1 frame of misaligned at the start. It's because you are turning rendering on at scanline 122, when it tries, mid-frame, to start rendering the top of the screen.
BG turns to red...
You are writing to the PPU (palette) on scanline 2. Then trying to set scroll mid-frame. And, not changing it during the next v-blank. Thus, the next frame is misaligned.
And, these should be reversed...
JSR FamiToneUpdate ; Update the music
JSR UpdateScroll ; Update the scroll values
As, every few frames, it doesn't get to updating the scroll position until 4+ scanlines of rendering have passed. It works, but it's poor timing.
Make sure you only write to screen during v-blank. Make sure that you only turn rendering ON or OFF during v-blank.
Definitely reverse the music update and the scroll update! The music code can be executed after the end of vblank without problems, but the scroll update absolutely must happen while still in vblank.
JWinslow23 wrote:
I was able to fix it myself through trial and error.
Even if the problem is (or appears to be!) fixed, it's important to understand what's happening.
dougeff wrote:
There is 1 frame of misaligned at the start. It's because you are turning rendering on at scanline 122, when it tries, mid-frame, to start rendering the top of the screen.
BG turns to red...
You are writing to the PPU (palette) on scanline 2. Then trying to set scroll mid-frame. And, not changing it during the next v-blank. Thus, the next frame is misaligned.
And, these should be reversed...
JSR FamiToneUpdate ; Update the music
JSR UpdateScroll ; Update the scroll values
As, every few frames, it doesn't get to updating the scroll position until 4+ scanlines of rendering have passed. It works, but it's poor timing.
Make sure you only write to screen during v-blank. Make sure that you only turn rendering ON or OFF during v-blank.
I literally copy-pasted the background code from Nerdy Nights back when I made my first demo, and I haven't bothered changing any of it
. I did, however, after enabling NMI, do a
JSR WaitFrame to wait until VBlank to enable rendering. I also reversed the positions of the calls to FamiToneUpdate and UpdateScroll.
tokumaru wrote:
Definitely reverse the music update and the scroll update! The music code can be executed after the end of vblank without problems, but the scroll update absolutely must happen while still in vblank.
JWinslow23 wrote:
I was able to fix it myself through trial and error.
Even if the problem is (or appears to be!) fixed, it's important to understand what's happening.
Well, to be honest, that was a spur-of-the-moment fix, and what I did exactly is call
JSR WaitFrame right before
JSR DeathAnimation in order to have that code start on VBlank, which I assumed would fix the problem.
My new source is attached, along with the .nes file. What else, if anything, do I need to do (or, what have I done wrong)?
Quote:
What else, if anything, do I need to do?
Let's talk BIG PICTURE.
Before you start coding, have an idea of how the game will play. Is this a platformer? or a shooter? Sketch up some levels in Photoshop.
You should divide the game into different 'modes'. Title mode. Game mode. Pause mode. Transition between level mode. Game over mode. Victory mode. Ideally, they would all share the same NMI code, but some modes might skip some things.
I would spend some time just getting the basic physics of the game working. *
I would then work on an automated system for drawing levels as you scroll. Preferably, by filling a vram update buffer, and setting a flag. Then, the NMI code will see the flag, and do an automated update.
I would then work on a sprite object system. Or, borrow someone else's working system. It should be an automated system, also. Like all you should have to do is tell it draw animation #2 at x = 50, y = 80, facing right, and it should arrange the tiles for you.
*Edit- for reference, no kidding, on a game I'm working on (not the Ninja game), the main character's movements alone takes up 1000 lines of code. That includes collision detections. It might take you MONTHS to get just the basics of the game in position.
This will be an arcade-style game, and it will play very similar to Flappy Bird. The walrus will fly around the screen as obstacles (I have mines, some will be stationary while others will move up and down towards the player) and collectibles (fish will give you points, and there might be some special invincibility object) fly past him horizontally. This keeps going until the maximum score is reached, or you die (whichever comes first). That's the gameplan, just like my
original Scratch project and my subsequent
Atari 2600 port.
I kinda figured I'd need modes to handle different game states, but I think I'll cross that bridge when I get there. I still got actual gameplay to worry about for a while.
By the way, "what else do I need to do" did not refer to general game programming, but rather, it referred to ways to fix problems with my existing code (like, was I
still drawing backgrounds and rendering outside of VBlank? or something). I've developed games before, but never for the NES, and I still have a lot of questions (which I will ask when I get to them).
While you aren't having problems (no PPU writes outside v-blank), you got lucky. It only works because your entire logic fits inside the v-blank, and on that frame the music code didn't push you just past v-blank.
It's the changing palette on death that I'm worried about.
So, this is where my lengthy 'game planning' post becomes relevant.
You need a vram update system. Inside the NMI code. And a control flag.
So you'd have a page of RAM dedicated to vram updates. 2 bytes for address. (3f00) 1 byte for length of data stream (1), and then follows the data (06), terminate with ff, or a new address, for another ppu update. An automated system. You can write to the vram buffer any time, then set a flag to inform the NMI code that you have an update ready. The NMI code will start at the start of v-blank, and automatically push your color change.