It is currently Tue Dec 12, 2017 1:08 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: First NES Project
PostPosted: Sun Aug 02, 2015 6:35 pm 
Offline
User avatar

Joined: Sat Jul 25, 2015 1:22 pm
Posts: 501
Hello everyone!

This weekend I finally took the leap and installed Windows and got to coding.

I wanted to try to do a simple project this weekend with some metasprites, animations, and maybe a little controls.

For the most part I succeeded at what I was doing but started having a few bugs at the end when I added horizontal flipping.

Would anyone be willing to check it out for me and give me any pointers? I'll post the source and NES file here if anybody thinks they'll read it. In the meantime I'm going to try to track down some of these bugs before I call it a night.

Oh yeah forgot to mention it's coded for ASM6 if that makes a difference.


Top
 Profile  
 
 Post subject: Re: First NES Project
PostPosted: Sun Aug 02, 2015 6:58 pm 
Offline
User avatar

Joined: Wed Apr 02, 2008 2:09 pm
Posts: 1046
Sure, post it. But also specifically what the bugs are. i.e. what you expect to happen, vs what happens.

_________________
https://kasumi.itch.io/indivisible


Top
 Profile  
 
 Post subject: Re: First NES Project
PostPosted: Sun Aug 02, 2015 8:39 pm 
Offline
User avatar

Joined: Sat Jul 25, 2015 1:22 pm
Posts: 501
Okay, here it is.

This is my very first project for NES.

It was actually working pretty well, up until not too long ago, I was adding features and somewhere along the way it started to mess up.

Okay, the main thing I was aiming to do was set up a system for Metasprites.

Right now it's set up so that I have to write a routine for each animation, but eventually I'd like to try to get it to where one routine can run all animations, if what I have is worth saving.

The program should show the girl standing, and go between walking and standing if you press A and B.

Left and right change her direction. This kind of works. It is arranging her tiles properly but her positioning is off. I have set it so that the center position should be able to be changed for each frame of animation but that doesn't seem to be working properly.

You can turn her between right and left when she's standing still when I haven't even programmed it to be able to do that. She shouldn't be able to turn right to left while standing. From loading the attributes for those tiles, they should default to unflipped, and I haven't programmed any flipping behavior for stand, just walk.

The main problem is the graphic glitches that pop up around the sprite and sometimes it doesn't delete frames. This hasn't happened a couple different times while I've been working on it and I fixed it a couple times, but I can't seem to figure out why this one is.


Attachments:
AnimationTest1.zip [5.66 KiB]
Downloaded 116 times
Top
 Profile  
 
 Post subject: Re: First NES Project
PostPosted: Sun Aug 02, 2015 9:47 pm 
Offline

Joined: Mon Apr 01, 2013 11:17 pm
Posts: 437
darryl.revok wrote:
You can turn her between right and left when she's standing still when I haven't even programmed it to be able to do that. She shouldn't be able to turn right to left while standing. From loading the attributes for those tiles, they should default to unflipped, and I haven't programmed any flipping behavior for stand, just walk.

Your "standing" code jumps into the middle of the "walking" code, probably because it uses the wrong label somewhere.

darryl.revok wrote:
The main problem is the graphic glitches that pop up around the sprite and sometimes it doesn't delete frames. This hasn't happened a couple different times while I've been working on it and I fixed it a couple times, but I can't seem to figure out why this one is.

Your NMI doesn't save and restore A, X, or Y, which means any use of those registers in the NMI will interfere with whatever is running when NMI hits.

You're constantly running the metasprite animator. You need some way to make it wait for NMI before it generates the next set of data.

The glitches are most likely caused by NMI clobbering registers in the middle of the metasprite routine. It's actually two bugs in one!


Top
 Profile  
 
 Post subject: Re: First NES Project
PostPosted: Mon Aug 03, 2015 1:21 am 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1866
Location: DIGDUG
Re: glitch tiles

Somehow your y offset is getting screwed up. This is causing an extra tile to be loaded at 220-223 which is a garbage tile. I'm not sure where the problem is, since your NMI code does not use x or y. The problem is somewhere between SkipStand: and SkipWalk:

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
 Post subject: Re: First NES Project
PostPosted: Mon Aug 03, 2015 4:58 am 
Offline
User avatar

Joined: Sat Jul 25, 2015 1:22 pm
Posts: 501
152 Branched to "ReadyForFrame" instead of "ReadyForStandFrame". Fixing this removed the bug allowing her to turn in stand state. She also now reverts to facing right when going back to stand as she should. "ReadyForFrame" is a label for the walk animation, but since it was the only one I had at the time, I didn't label it as such.

One of the LDAs on 192 or 196 was referencing WalkYOffset instead of StandYOffset.

I commented out some of the direction code right now to try to figure it out.

The biggest graphic glitch I keep seeing is that the top left space keeps getting (seemingly) random tiles with what may be randomly rotation.

Joe wrote:
You're constantly running the metasprite animator. You need some way to make it wait for NMI before it generates the next set of data.


If the code is working properly, it shouldn't be addressing the PPU during the animation subroutine. It should just be writing tile data to $0200-$0207 and then OAM DMAing that to the PPU during NMI. Is that a valid way to do this?


Top
 Profile  
 
 Post subject: Re: First NES Project
PostPosted: Mon Aug 03, 2015 5:46 am 
Offline
User avatar

Joined: Sat Jul 25, 2015 1:22 pm
Posts: 501
I think I fixed it!

Most of the problem was due to the fact that I had my data entered incorrectly with two end of frame tags in a row.

I'm going to upload an updated version and see if I can get anyone's opinion on whether or not this animation code is any good and whether or not it's worth building on for a game engine, or if it was just good for a learning experience.

Any advice, tips, suggestions, would be very appreciated. I'm new to 6502 and I've never been a professional programmer so I know I have a lot to learn.

I applied different frame delays to each from of the walk cycle to show that's working.

I also put a delay loop in the main program data to make the animation behave as if there was game code running.

I applied different rotate axis values for different frames of the walk animation to show that that's working. So if you face left while walking, her position will shift.

It looks like it's mostly working just how I'd expect. I did see some glitch sprites on the Y offset like you mentioned, but I couldn't get it to repeat. Hopefully I'll track it down soon but I think I have the bulk of this code functioning now.


Attachments:
AnimationTest1MaybeFixed.zip [5.71 KiB]
Downloaded 97 times
Top
 Profile  
 
 Post subject: Re: First NES Project
PostPosted: Wed Aug 05, 2015 10:10 am 
Offline

Joined: Mon Apr 01, 2013 11:17 pm
Posts: 437
darryl.revok wrote:
If the code is working properly, it shouldn't be addressing the PPU during the animation subroutine. It should just be writing tile data to $0200-$0207 and then OAM DMAing that to the PPU during NMI. Is that a valid way to do this?

You've got the right idea, but your implementation has some flaws:
  • Your NMI clobbers A
  • Your "game loop" isn't synchronized to NMI
  • Your NMI will start DMA even if the animation subroutine isn't done writing tile data

This combination is most likely responsible for the remaining glitches you see. Since you aren't synchronizing your "game" to NMI, there is a chance NMI will occur while the animation subroutine is running. If this happens, it will start the DMA even if the tile data is incomplete, and when it returns, A will no longer have the correct value, causing the animation subroutine to misbehave.

Fixing NMI to not clobber A is easy: push A to the stack right at the beginning of NMI, and pull A from the stack right at the end.

Synchronizing the game loop to NMI is a little more difficult. One popular method is to have a variable in RAM that is incremented every time NMI runs. When your game code is waiting for NMI, it loads that variable in a register, and then loops comparing the variable to the register until they aren't equal.

When your NMI is more fully-featured, you'll probably want some way to control which tasks it performs, so it doesn't try to upload incomplete data to the PPU. Your animation test is small enough that it will always have enough time to finish its tasks between one NMI and the next, so you don't have to worry about fixing the third issue yet.


If I were to implement this myself (which is another way of saying "you can ignore this if you like your way better"), I would try to make my drawing code flexible enough to draw all of the different player animations, instead of writing new code for each set. I would use lots of tables of pointers to tables, and maybe even cache the pointers so I could skip some of the table lookups when the indices haven't changed.


Top
 Profile  
 
 Post subject: Re: First NES Project
PostPosted: Fri Aug 07, 2015 7:15 am 
Offline
User avatar

Joined: Sat Jul 25, 2015 1:22 pm
Posts: 501
Wanted to post an updated version of this in case anybody wanted to check it out. There's a .NES file as well as the source, and the CHR. I think I forgot to add the CHR last time.

I'm probably going to do a full rewrite of the way data is stored and integrate CHR bank-switching, so I figured I'd post this up beforehand and see if anybody has any comments before I do.


Attachments:
Animation Engine 2.zip [13.22 KiB]
Downloaded 85 times
Top
 Profile  
 
 Post subject: Re: First NES Project
PostPosted: Wed Aug 12, 2015 8:53 pm 
Offline
User avatar

Joined: Mon Oct 06, 2014 12:37 am
Posts: 187
Neat demo! It's interesting to see somebody tackling animation code, first!

This is just my opinion, but looking at your code, it seems a bit silly to have a routine for mirroring.
Why not just merge it into your animation frame data?

I would suggest a frame set-up, like this. Though, I work in NROM, so the workspace is lesser.
(Just a heads up, the sprite mirroring should be moved to the frame timing, not the frame index.)
I'm in the middle of fixing my code, from that silly mistake. Heh.

Code:
; Byte 0, Frame Number
; --FFFFFF = 6-bit frame number, (0-63)
; MM------ = 2-bit sprite mirroring

; Byte 1, Frame Timer
; xxxxxxxx = 8-bit frame time, (6 / 0.1)


Example:
$00,$06,$40,$06 ; Walk South (H-Flip)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group