Program music from Famitracker into game?

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

User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: Program music from Famitracker into game?

Post by DRW »

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.
Last edited by DRW on Thu Apr 27, 2017 4:35 pm, edited 1 time in total.
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
User avatar
JWinslow23
Posts: 30
Joined: Mon Apr 24, 2017 5:52 am
Location: West Allis, WI

Re: Program music from Famitracker into game?

Post by JWinslow23 »

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?
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: Program music from Famitracker into game?

Post by DRW »

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.
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
User avatar
JWinslow23
Posts: 30
Joined: Mon Apr 24, 2017 5:52 am
Location: West Allis, WI

Re: Program music from Famitracker into game?

Post by JWinslow23 »

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?
Attachments
famitone2.asm
The library (had to put colons after every define for it to compile, but that's all I modified).
(28 KiB) Downloaded 99 times
walrush_music.asm
The generated music file.
(2.01 KiB) Downloaded 106 times
walrush.asm
The game file I actually compile.
(18.45 KiB) Downloaded 103 times
User avatar
JWinslow23
Posts: 30
Joined: Mon Apr 24, 2017 5:52 am
Location: West Allis, WI

Re: Program music from Famitracker into game?

Post by JWinslow23 »

Bump.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Program music from Famitracker into game?

Post by dougeff »

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.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
JWinslow23
Posts: 30
Joined: Mon Apr 24, 2017 5:52 am
Location: West Allis, WI

Re: Program music from Famitracker into game?

Post by JWinslow23 »

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?
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Program music from Famitracker into game?

Post by tepples »

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.
User avatar
JWinslow23
Posts: 30
Joined: Mon Apr 24, 2017 5:52 am
Location: West Allis, WI

Re: Program music from Famitracker into game?

Post by JWinslow23 »

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.
Attachments
walrush.chr
The .chr file (can't believe I forgot to upload this).
(8 KiB) Downloaded 91 times
walrush.asm
The .asm file.
(18.83 KiB) Downloaded 89 times
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Program music from Famitracker into game?

Post by dougeff »

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.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
JWinslow23
Posts: 30
Joined: Mon Apr 24, 2017 5:52 am
Location: West Allis, WI

Re: Program music from Famitracker into game?

Post by JWinslow23 »

Sorry, I'll upload the .nes file.

EDIT: Never mind, I was able to fix it myself through trial and error. Still, thanks!
Attachments
walrush.nes
Here it is.
(24.02 KiB) Downloaded 100 times
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Program music from Famitracker into game?

Post by dougeff »

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.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Program music from Famitracker into game?

Post by tokumaru »

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.
User avatar
JWinslow23
Posts: 30
Joined: Mon Apr 24, 2017 5:52 am
Location: West Allis, WI

Re: Program music from Famitracker into game?

Post by JWinslow23 »

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 :P. 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)?
Attachments
walrush.nes
The .nes file.
(24.02 KiB) Downloaded 97 times
walrush.asm
The .asm file.
(18.95 KiB) Downloaded 90 times
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Program music from Famitracker into game?

Post by dougeff »

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.
Last edited by dougeff on Fri Apr 28, 2017 12:48 pm, edited 1 time in total.
nesdoug.com -- blog/tutorial on programming for the NES
Post Reply