Optimizing the usage of character-related data

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: Optimizing the usage of character-related data

Post by DRW »

I assume there's no way to prevent the cc65 compiler from using the X register in C code, right?
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Optimizing the usage of character-related data

Post by Oziphantom »

CC65 is basically 16bit so it uses AX for everything.
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: Optimizing the usage of character-related data

Post by DRW »

That's unfortunate.

I guess I have to try to reduce the variables then.

Unless there's some other trickery to copy variables in a faster way.

For example, if I store the variables of the 10 opponents into 10 arrays, and one array is my local buffer array where the data gets copied to, is there a way to bulk-copy an array into another array that's faster than individual LDAs and STAs?
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: Optimizing the usage of character-related data

Post by calima »

Not on NES. SNES would have that.
turboxray
Posts: 348
Joined: Thu Oct 31, 2019 12:56 am

Re: Optimizing the usage of character-related data

Post by turboxray »

DRW wrote: Thu Jun 30, 2022 3:43 pm
Oziphantom wrote: Thu Jun 30, 2022 2:28 amFacingDirection, UntouchableStatus, HorizontalDirection, VerticalDirection, PatternIsAdditional, HorizontalDirectionBeforeThrownAway, VerticalDirectionBeforeThrownAway, LastHorizontalFacingDirection
these all seem to be bool flags, so 1 bit.
Unfortunately no. The direction variables are up, down, left, right, none. Untouchable status is also a counter value for mercy invincibility. Only PatternIsAdditional is an actual boolean value.
You can fit FacingDirection, HorizontalDirection, VerticalDirection, HorizontalDirectionBeforeThrownAway, and VerticalDirectionBeforeThrownAway all in a single byte. I'm assuming you're doing stuff like "if (HorizontalDirection) {..}", then a hit like "if (HorizontalDirection & MASKhoriDirection) {..}" should be an extra 2 cycles for the immediate AND instruction. I mean if the C code isn't that optimal, you appear to already know how to code in some fashion of ASM.. so you could implement this yourself. You don't specifically need N and V flags for optimization.

Like you said, do you really need all 35 bytes? I see that you have a few different state machines there.. I would streamline that if you don't have state machines that can/do run in parallel, then don't bother grabbing other state machine related indexes/support values. How many "objects" are you parsing through in a single frame? 4, 5,.. 10? Is this data structure only for "enemies" or do you re-use it for "items" as well? Do you have an active/de-active area mechanism in this game?


Honestly though, no one asked the question.. do you actually need to optimize your code? Is this something you're doing pre-emptively in order to avoid some future potential issue.. or is this an issue right now?? If it's an issue right now, what performance profile have your run on your game? Since this appears to be a complicated area to untangle and optimize (i.e. a heavier lift for refactoring), what other simpler support functions have you benchmarked that could provide some low hanging fruit for optimization? (Replace some of the simple functions with ASM code).
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Optimizing the usage of character-related data

Post by tepples »

Oziphantom wrote: Fri Jul 01, 2022 9:39 am ok coding in c... cc65? to which best bet is just use a better C compiler, port to Kick-C for best performance but harder to code in. Or VBCC,however LLVM-MOS is probably not ready for the prime time yet.
Using VBCC is fine, provided that you know for certain that one of the following is the case:
  1. you are targeting MEGA65 hardware (not NES),
  2. you are targeting AmigaOS on 68K, or
  3. you plan to never distribute for a fee any copies of the compiled code. This provision is incompatible with distribution on cartridge, incompatible with paid downloads bundled with an emulator on Steam or modern consoles, and incompatible with the submission policy of NESdev Compo.
(Source: its manual (PDF))

In February 2021, I received a quote from the author that a license for commercial use of vbcc targeting the NES might cost on the order of 100 USD.
(Source: vbc's post in topic "VBCC Optimizing C-compiler now supports NES")
DRW wrote: Sat Jul 02, 2022 7:36 am I'd still like to know what different approaches commercial games used. Did they use array access and actually kept the X register? Or did they do other stuff?
The commercial NES games Haunted: Halloween '85, Haunted: Halloween '86, and (forthcoming) Full Quiet use array access and keep the current actor's index in the X register most of the time.

These games are also commercial because they have appeared in an Action 53 volume:
  • Thwaite keeps the index of the current crosshair, missile, explosion, or smoke particle being operated on in X.
  • RHDE: Furniture Fight keeps the index of the current player, unit, or missile in X.
User avatar
aquasnake
Posts: 515
Joined: Fri Sep 13, 2019 11:22 pm

Re: Optimizing the usage of character-related data

Post by aquasnake »

Optimize characters, and dynamically generate characters using mirroring algorithm like game genie?

To save 8KB CROM? It's better to write one screen of data to cram in advance by using unrom
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Optimizing the usage of character-related data

Post by Oziphantom »

they are using character to reference actor or unit in the game, a story character not a letter to be displayed on the screen.
Post Reply