nesdev.com
http://forums.nesdev.com/

Program music from Famitracker into game?
http://forums.nesdev.com/viewtopic.php?f=2&t=15865
Page 2 of 3

Author:  DRW [ Thu Apr 27, 2017 4:32 pm ]
Post subject:  Re: Program music from Famitracker into game?

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.

Author:  JWinslow23 [ Thu Apr 27, 2017 4:35 pm ]
Post subject:  Re: Program music from Famitracker into game?

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?

Author:  DRW [ Thu Apr 27, 2017 4:37 pm ]
Post subject:  Re: Program music from Famitracker into game?

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.

Author:  JWinslow23 [ Thu Apr 27, 2017 4:42 pm ]
Post subject:  Re: Program music from Famitracker into game?

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:
File comment: The library (had to put colons after every define for it to compile, but that's all I modified).
famitone2.asm [28 KiB]
Downloaded 20 times
File comment: The generated music file.
walrush_music.asm [2.01 KiB]
Downloaded 15 times
File comment: The game file I actually compile.
walrush.asm [18.45 KiB]
Downloaded 21 times

Author:  JWinslow23 [ Thu Apr 27, 2017 6:38 pm ]
Post subject:  Re: Program music from Famitracker into game?

Bump.

Author:  dougeff [ Thu Apr 27, 2017 8:55 pm ]
Post subject:  Re: Program music from Famitracker into game?

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.

Author:  JWinslow23 [ Thu Apr 27, 2017 11:01 pm ]
Post subject:  Re: Program music from Famitracker into game?

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?

Author:  tepples [ Fri Apr 28, 2017 4:36 am ]
Post subject:  Re: Program music from Famitracker into game?

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.

Author:  JWinslow23 [ Fri Apr 28, 2017 8:04 am ]
Post subject:  Re: Program music from Famitracker into game?

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:
File comment: The .chr file (can't believe I forgot to upload this).
walrush.chr [8 KiB]
Downloaded 17 times
File comment: The .asm file.
walrush.asm [18.83 KiB]
Downloaded 21 times

Author:  dougeff [ Fri Apr 28, 2017 8:28 am ]
Post subject:  Re: Program music from Famitracker into game?

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.

Author:  JWinslow23 [ Fri Apr 28, 2017 8:49 am ]
Post subject:  Re: Program music from Famitracker into game?

Sorry, I'll upload the .nes file.

EDIT: Never mind, I was able to fix it myself through trial and error. Still, thanks!

Attachments:
File comment: Here it is.
walrush.nes [24.02 KiB]
Downloaded 21 times

Author:  dougeff [ Fri Apr 28, 2017 10:25 am ]
Post subject:  Re: Program music from Famitracker into game?

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.

Author:  tokumaru [ Fri Apr 28, 2017 11:04 am ]
Post subject:  Re: Program music from Famitracker into game?

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.

Author:  JWinslow23 [ Fri Apr 28, 2017 11:30 am ]
Post subject:  Re: Program music from Famitracker into game?

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:
File comment: The .nes file.
walrush.nes [24.02 KiB]
Downloaded 18 times
File comment: The .asm file.
walrush.asm [18.95 KiB]
Downloaded 20 times

Author:  dougeff [ Fri Apr 28, 2017 12:34 pm ]
Post subject:  Re: Program music from Famitracker into game?

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.

Page 2 of 3 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/