NES games with a lot of character logic going on

You can talk about almost anything that you want to on this board.

Moderator: Moderators

Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: NES games with a lot of character logic going on

Post by Oziphantom »

What do you mean? Do you simply mean that buffering values in variables is faster than looking them up in arrays? Or do you mean that accessing RAM would be faster than accessing ROM, so that code runs faster when I copy it to RAM first?
it helps with everything.
So while you can look up tables in ROM, you also have to have the table in the same ROM as your code, maybe that works maybe it doesn't. But you will still need to read a value from an index into another index and then look up the value, vs just read the value. The fast calculations are the ones you don't have to do.
So how often do you need to update the collision, well once the object leaves its current spot and crosses a "boundary" when does it do that? well you can mostly work that out on the fly, but then you only want to change the state or do more logic if that value changes, i.e its going left and it was on ground and still is on ground then do nothing, no change to make. Knowing what it was on is faster. But you need RAM to cache it.

Ent to Ent collision, having an X or Y sorted table really speeds it up, as you will know what a sprite can stop checking faster. I.e you know the sprite is 16 pixels high, then once you get to entity that is above y+16 you abort, as no entity down the list can collide with you. Y tables need RAM. Do I look up its 16 high, or do I just store my table of upper Ys, lower Ys, lower Xs, upper Xs. When I inc y I just inc both, dec x etc but this way I don't need to look up the ent size, by getting its type, moving to the right ROM bank, reading, doing the maths and doing the compare again and again as I loop through, I just read them all with the same index.

Need to look up 2d data, such as map collision data, put each row into its own page so you have 10 rows then you can storeY into the hi, keep the lo 0, and then lda (zp),y where y is the x index. But you have RAM and now you can self mod, so
lda $XX00,y is 4 clocks, not 5, but then you don't have to keep 2 ZP locations, you don't have to store the lower as 0 to be sure, it will always be zero, you just write the the XX byte and go. Don't want to trash the y for this, then store X in the 00 and don't use y. Need to use a value again down the code, don't waste a ZP that is precious, just store the value into the param of a LDA, LDX, LDY # ahead when you need it again, its smaller and faster.
You can build unrolled loop to handle each entity update you currently have on the screen to avoid doing loops and look ups each time. I.e you know entity 2 is a Bat and so you can just

Code: Select all

ldx #0
jsr routine
ldx #1
jsr routine
ldx #2
jsr routine ; set this to be the bat update
this way you skip any "look up type of ent and dispatch logic".
RAM is speed, it boosts practically every aspect of code, reduces index pressure, smaller code, faster code, gives you more ZP back for other optimizations.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NES games with a lot of character logic going on

Post by Pokun »

DRW wrote: Thu Mar 17, 2022 3:38 pm In "T.M.N.T.", I've seen scenes with five enemies at once.
But in "Ninja Gaiden", I haven't seen more than three non-projectile opponents on screen.
In "Gimmick", I didn't find extreme situations either.
It would be good if you could name me specific sections of the game.
Yeah TMNT is the first busy game that came up in my mind except Rockman. The Fire Freaks on stage 3 tends to create small clones (looks like fiery legs to me) and can easily make the screen full of enemies IIRC. Projectiles and flying enemies are generally quite simple though. It might get busier in the final levels, but I've never beaten this game. :lol:

Ninja Gaiden 3 final level (stage 7) sometimes has 4 walking enemies at once, though they seems to be slow-moving. All Ninja Gaiden final levels tends to have a lot of fast enemies in general, but maybe seldom more than 3 at a time. Flying enemies (except bats) tends to have much more complex patterns than the usual straight-line projectiles most games has.

Gimmick doesn't have a lot of simultaneous objects, but it has very seemingly complex objects with complex physics. I guess that's not what you were looking for though.
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: NES games with a lot of character logic going on

Post by DRW »

Pokun wrote: Fri Mar 18, 2022 8:26 am Yeah TMNT is the first busy game that came up in my mind except Rockman. The Fire Freaks on stage 3 tends to create small clones (looks like fiery legs to me) and can easily make the screen full of enemies IIRC.
Do you have a time stamp? Stage 3 is a huge ass area and I cannot find the passage that you're referring to.
Pokun wrote: Fri Mar 18, 2022 8:26 am Ninja Gaiden 3 final level (stage 7) sometimes has 4 walking enemies at once, though they seems to be slow-moving. All Ninja Gaiden final levels tends to have a lot of fast enemies in general, but maybe seldom more than 3 at a time.
Yeah, that's the thing: I still consider three or even four enemies normal. I mean, even my own game, my first attempt at NES programming, written in C for the most part, manages lag-free three opponents at any given time.

I'm talking about really extreme examples. Is there a game where 10 opponents storm at the player at once? No? How about nine? Eight? Seven? I need to see where the limit was in actual games. So, of course I don't consider "Ninja Gaiden" a limit-pushing game, just because it might have four enemies on screen now and then. (Well, unless this really is the limit and no other game ever attempted more.)
Pokun wrote: Fri Mar 18, 2022 8:26 am Flying enemies (except bats) tends to have much more complex patterns than the usual straight-line projectiles most games has.
Depending on what you mean with complex, it might still just be x += XOffsets[CurrentIndex++];.
Pokun wrote: Fri Mar 18, 2022 8:26 am Gimmick doesn't have a lot of simultaneous objects, but it has very seemingly complex objects with complex physics. I guess that's not what you were looking for though.
Indeed, it was not, since the character doesn't do all of that in one single frame. A fighting game has the most complex enemy movement, but I would say that the game logic would be one of the least challenging for the NES hardware. (A fighting game would have other issues, like large characters being a flicker fest.)
But if "Super Mario Bros." had 20 Goombas and winged Koopa Troopas on screen at once, despite their relatively simple movement pattern, this would surely lag due to all the physics calculations with the stage, the collision detection with each other and the fact that all of that is done for so many enemies at once.
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NES games with a lot of character logic going on

Post by Pokun »

At the beginning of stage 3 the first building you normally encounter and use to stock up on missiles in has a ton of enemies right away. Depending on which set of enemies you get it may include the Fire Freak. In that longplay the status bar flickers for some reason at some point after he takes the missiles and is on his way out.

I believe the mechanics of some enemies in Ninja Gaiden are more complex than those in say TMNT where they mostly just walk following the player and shoots, or move back and forth between walls like a Koopa Troopa. Ninja Gaiden enemies has a number of patterns that they cycle through. They might first go to a certain position, jump around a bit then charge the player position and repeat. Birds also does something similar.
Hmm well now that I think about it some more, I guess it just means there are a number of extra state machine state checks, so this extra complexity might actually not affect performance by much, mostly only more ROM space for the extra code needed.


As for fighting games what about the Kunio-kun games? Even the sport-themed Kunio-kun games plays using similar mechanics as fighting games, and physics typically works in 3 dimensions (though limited). Dodgeball and Soccer both has a bunch characters, a ball and 3D-physics.


I can't think of many non-STGs that has more than 5 complex enemies, so maybe the typical limit is around that.
Wait, what about Bubble Bobble? Here are 7 Maita, that's 9 characters if both Bubblun and Bobblun are present. They are not too complex but they at least all individually have to obey the same laws of physics. Their glowballs goes in a straight line, but the players' bubbles follows much more complex rules (although the air-streams might be hardcoded for each level). I have mostly played the arcade version and the Game Boy version, so I'm not sure how many bubbles the NES version allows, but normally you can produce a ton of them before they are forced to pop by the game rules.
hackfresh
Posts: 101
Joined: Sun May 03, 2015 8:19 pm

Re: NES games with a lot of character logic going on

Post by hackfresh »

Tecmo super bowl(football) 11 vs 11 can have a lot going on.

It uses some of the tricks mentioned in this thread.

1. Entity logic only gets run once the timer runs out.
Example ball carrier pursuit. It only checks after so
frames to adjust to the ball carriers direction. Hence
why you can zig-zag your way down the field vs the
computer.

2. When the players are collided that frees up time.

The game does get laggy when there are a lot of
fast uncollided players chasing a ball carrier. Typically
it only slows down during punt returns.

The sprite order cycling takes up a good chunk of
the cpu time.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: NES games with a lot of character logic going on

Post by Dwedit »

Sprite order cycling is so easy when you use the "just add 9" trick...
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NES games with a lot of character logic going on

Post by Pokun »

How does that work? You just add 9 to each sprite number?
I guess it won't work if you have certain sprites you don't want to redesignate, like sprite 0.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: NES games with a lot of character logic going on

Post by tokumaru »

Pokun wrote: Sat Mar 19, 2022 2:00 pmHow does that work? You just add 9 to each sprite number?
Yeah, you just start filling OAM from a random position and advance a number of slots that's relatively prime to 64, such as 9 or 17.
I guess it won't work if you have certain sprites you don't want to redesignate, like sprite 0.
Using a BEQ instruction to skip slot 0 is simple enough, but this indeed isn't a technique that can be used in all situations. If you need to respect any sort of sprite layering, things will have to be more complex than this.
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: NES games with a lot of character logic going on

Post by DRW »

Pokun wrote: Fri Mar 18, 2022 3:21 pm At the beginning of stage 3 the first building you normally encounter and use to stock up on missiles in has a ton of enemies right away. Depending on which set of enemies you get it may include the Fire Freak. In that longplay the status bar flickers for some reason at some point after he takes the missiles and is on his way out.
Thanks. I found a section where those fire opponents appear. Not only do they create clones of themselves, but you can even spawn a whole bunch of the main versions in a little gap where they cannot escape. I activated an invincibility cheat. Later, I'll have a look how many enemies exactly are possible before the game starts lagging.
Pokun wrote: Fri Mar 18, 2022 3:21 pm As for fighting games what about the Kunio-kun games? Even the sport-themed Kunio-kun games plays using similar mechanics as fighting games, and physics typically works in 3 dimensions (though limited). Dodgeball and Soccer both has a bunch characters, a ball and 3D-physics.
Those games surely have a lot of characters, although often I see players that are farther away do nothing at all or walk senselessly in circles.
Then there's the fact that many players of a team are usually outside the screen and probably aren't processed at all. It's not like all six opponents and your team members ever get on the screen at once.
Also, these games don't really have a level structure since it's just a plain rectangle.
So, it's not really comparable to a game where you have many actual enemies doing independent stuff in a real level.


Same with "Tecmo Super Bowl": While it does have more opponents on screen, it again has no level structure, just an open field.

Pokun wrote: Fri Mar 18, 2022 3:21 pmWait, what about Bubble Bobble? Here are 7 Maita, that's 9 characters if both Bubblun and Bobblun are present.
Now we come closer what I have in mind.
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NES games with a lot of character logic going on

Post by Pokun »

tokumaru wrote: Sat Mar 19, 2022 3:42 pm
Pokun wrote: Sat Mar 19, 2022 2:00 pmHow does that work? You just add 9 to each sprite number?
Yeah, you just start filling OAM from a random position and advance a number of slots that's relatively prime to 64, such as 9 or 17.
I guess it won't work if you have certain sprites you don't want to redesignate, like sprite 0.
Using a BEQ instruction to skip slot 0 is simple enough, but this indeed isn't a technique that can be used in all situations. If you need to respect any sort of sprite layering, things will have to be more complex than this.
So a branch every time a sprite reaches an illegal position? Won't there be a chance that the sprite lands on a used position in that case?

I suppose sprite layering could be handled by each metasprite, and you would just cycle the whole metasprite together. RPGs like Dragon Quest does this in the walkabout mode as all metasprites are normally of equal size (DQ games just advances all sprite numbers by 4 every frame or so). Contra seems to move every sprite individually and in random positions with no relation to other sprites of the same metasprite.

DRW wrote: Sun Mar 20, 2022 5:04 am
Pokun wrote: Fri Mar 18, 2022 3:21 pm As for fighting games what about the Kunio-kun games? Even the sport-themed Kunio-kun games plays using similar mechanics as fighting games, and physics typically works in 3 dimensions (though limited). Dodgeball and Soccer both has a bunch characters, a ball and 3D-physics.
Those games surely have a lot of characters, although often I see players that are farther away do nothing at all or walk senselessly in circles.
Then there's the fact that many players of a team are usually outside the screen and probably aren't processed at all. It's not like all six opponents and your team members ever get on the screen at once.
Also, these games don't really have a level structure since it's just a plain rectangle.
So, it's not really comparable to a game where you have many actual enemies doing independent stuff in a real level.
Ah right, Dodgeball and Soccer both lacks walls and pits. Downtown, Daiundoukai, Kakutou Densetsu and Downtown Jidaigeki all has 3D level structure and the latter two even has slopes, ladders, spikes, conveyor belts and other architecture, but these games seems to have less characters, typically 4 at a time.
Drag
Posts: 1615
Joined: Mon Sep 27, 2004 2:57 pm
Contact:

Re: NES games with a lot of character logic going on

Post by Drag »

Pokun wrote: Sun Mar 20, 2022 5:57 am So a branch every time a sprite reaches an illegal position? Won't there be a chance that the sprite lands on a used position in that case?

Code: Select all

 LDA currSpriteIndex
 JSR putSprite
skip:
 CLC
 ADC #$24 ; constant 1
 BEQ skip
 STA currSpriteIndex
 RTS

vblank:
 LDA startSpriteIndex
 CLC
 ADC #$20 ; constant 2
 STA startSpriteIndex
 STA currSpriteIndex
 ...
 RTS

reset:
 LDA #$04
 STA startSpriteIndex
 STA currSpriteIndex
 ...
It's something like this. The idea is, if you've reached a sprite index which is already in use, it's because you've filled out all 62 other sprite slots (slot 0 not counted) and you've rolled back over to where you started. I use different constants in my code, but this is essentially what I do for OAM shuffling too. You can use a BCS instead of a BEQ, and you'll skip the first N sprites (where N = constant 1) if you need to have a space where you can control the order of your sprite tiles.
Post Reply