News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: New Tools for Red Falcon  (Read 3475 times)

Trax

  • Hero Member
  • *****
  • Posts: 530
    • View Profile
    • Trax ROM Hacking
New Tools for Red Falcon
« on: August 22, 2015, 01:51:12 pm »
In addition to RotRF and the Secret Project, I started working on new tools for Red Falcon that aim to make customization easier and more flexible. None of them are fully functional yet, but the GUI is going well and displays data correctly...

First, a block editor. I tend to use the word "tile" interchangeably, but it will cause confusion sooner or later. A tile should refer to a 8x8 pixels square, the smallest unit of graphics on the NES. In Contra, all levels are made of "blocks" of 4x4 tiles, so 32x32 pixels. Each block has its own ID, and 0x10 bytes for each of the tiles that compose it, starting from the top-left corner, going right, then down. Very straightforward. The data for the blocks tile mappings starts right at the beginning of bank 3, at 0xC001. The pointer to the data for each level is in the headers (0xB319, bank 2) at offset 04-05. There's also the palette mappings, 1 byte per block, offset 06-07. Each 2x2 tiles corner of a block is set to one of the 4 background palettes, with 2 bits per corner. This is also standard stuff...

One thing that can become problematic is that there's no way for the editor to know where the tiles data for a given level stops. In this window (just like the main level editor window), I simply set the max number of tiles to 0x80, even though no level goes that far. That's the reason why you can see garbage if you scroll all the way down to the bottom of the block selection matrix. Even if you choose to use one of these garbled tiles, it should show up as is when you play the game...

This means there will be some sort of field where you can input the number of tiles to save for each level. Saving 0x80 tiles worth of data for every level would be wasteful. And we would probably end up with a lack of free space, anyway. Before that, it was not important since block editing was not possible, so it was limited to reading, not saving after modification. So, small caveat here, but important to consider...

Then, we have the Collision Limits Editor. In Contra, like many other games, collisions are (unfortunately) tile-based, not block-based. Each of the 256 tiles can be associated to one type of collision. The four types of collision are Transparent (no collision), Ground (solid from above only), Water (changes the player's status and limits movements, like jumping), and Solid (blocks the player from all sides). The way Collision Limits are programmed is... limited. Like, 3 bytes. That's it. You can find the bytes relative to Collision Limits in the header of each level, offset 09-0B...

This is what the first level's Collision Limits look like. Like all other levels, the majority of the tiles are Transparent. Each of the 3 bytes in the header defines a boundary between the different types of tiles. This means you are forced to have all the tiles of a same type placed contiguously in the PPU. The first tile is always Transparent (Code 0) by definition. Then, all tile indexes lower than the first byte (in this case, 06) are of type Ground. Then, all tiles lower than the second byte, F9, are Transparent. And all the tiles lower than the third byte, FF, are Water. The remaining tile, FF, is Solid...

Interestingly, only the first level has Water tiles, and Collision Limits that go with it. All other levels have the second and third bytes equal. Which means that mathematically, no tile is associated to Water collision. Another thing to consider: Collision Limits are also modified along with the graphics data when approaching a level's boss. In level 1, a lot more tiles, those used for the Barricade, become Solid (code 3)...

And finally, a Sprite Editor. You can see all the tiles that compose the sprite in the table on the right. Columns, from left to right: tile index, tile code, X coordinate, Y coordinate, palette code, flipping. X/Y coordinates can be negative, 0,0 being the actual position of the sprite.



Sprites in Contra are very flexible. The big-ass table at 7030 (bank 1) contains pointers (0xCF pointers) for every sprite in the game. The sprite data follows immediately. Each entry starts with a tile count, followed by that many groups of 4 bytes for each tile. However, its flexibility is also what makes it a little more complicated to edit. Some data in the data table has no pointer associated to it. Instead, they are "follow-ups" to other sprites. There's a special code, 0x80, that lets you change the offset of the reading head for sprite data, and go on from there. This way, you can recycle some parts of the data table for similar sprites that have tiles in common...

For example, take the Weapon Items. They all have the same common wing tiles, but a different middle part. So each of the sprites start with the middle part, then use code 0x80 to skip to the same wing tiles part. The wing part in itself is not a sprite, therefore no entry in the pointer table points to it. Yet, the data is still there, mixed with the rest...

There's also another special code, 0xFE, sometimes seen right at the beginning of a sprite data entry, in lieu of the tile count. I'm not sure exactly how this works, but it seems to be a short version of a single tile. The entry contains only 3 bytes, including the 0xFE code. Little sprites, like bullets, use this data structure...

Reading from the data is relatively trivial, but when it will be time to modifiy the sprites and save, things will become a little more complicated. Maybe we'll have to deal with a list of "orphaned" sprite data, along with the "regular" entries associated to a pointer...

So that's it for now. I think these tools will be essential to making a Contra hack that doesn't look like the original game at all. No graphics editor yet, but it's in the plans. Oh, and a data editor is also in the works...

Any ideas or questions?

Chpexo

  • Hero Member
  • *****
  • Posts: 731
    • View Profile
.
« Reply #1 on: August 22, 2015, 02:03:26 pm »
.
« Last Edit: January 01, 2016, 12:18:45 pm by Chpexo »

NiO

  • Jr. Member
  • **
  • Posts: 87
  • Let's bring order to chaos
    • View Profile
    • https://www.facebook.com/groups/retrogamersmx/
Re: New Tools for Red Falcon
« Reply #2 on: August 23, 2015, 11:38:47 pm »
is there a way I can use this on windows?
like an emulator to run this program?  :-[

snarfblam

  • Submission Reviewer
  • Hero Member
  • *****
  • Posts: 590
  • CANT HACK METROID
    • View Profile
    • snarfblam
Re: New Tools for Red Falcon
« Reply #3 on: August 24, 2015, 06:21:22 pm »
As for the Windows version, I won't do it myself, but I am working on a comprehensive document where I explain the main parts of the game, where to get the data and maybe some explanation on how I did it, so that someone else can use it as a reference.

I'll be happy to make an editor for anything that's documented.

NiO

  • Jr. Member
  • **
  • Posts: 87
  • Let's bring order to chaos
    • View Profile
    • https://www.facebook.com/groups/retrogamersmx/
Re: New Tools for Red Falcon
« Reply #4 on: August 24, 2015, 09:48:25 pm »
I'll be happy to make an editor for anything that's documented.

oohh man, that would be so damn awesome  :o


Trax

  • Hero Member
  • *****
  • Posts: 530
    • View Profile
    • Trax ROM Hacking
Re: New Tools for Red Falcon
« Reply #5 on: September 12, 2015, 12:58:31 pm »
For your information, guys. I tried to get Cocotron working, and as expected, it was a nightmare. Cocotron is an Objective-C cross-compiler for Windows and Linux. I went through a few of the first steps successfully, but then it was a mash-up of missing libraries and undecipherable error codes. My computer is not the most neat, so it's very possible there were some problems in there even before I got started. Plus, the documentation is quite limited. I just lost a lot of time with it and I don't think it's worth my time. I prefer to do things more productive...

I did some serious work on a document that compiles all I know about Contra, pointer tables offsets and the data structures. There's quite a lot to cover, but at least it's progressing. If Snarfblam or anyone else is interested, it will prove very useful. Until then, get your hands on a Mac if you want to try Red Falcon...

NiO

  • Jr. Member
  • **
  • Posts: 87
  • Let's bring order to chaos
    • View Profile
    • https://www.facebook.com/groups/retrogamersmx/
Re: New Tools for Red Falcon
« Reply #6 on: September 13, 2015, 10:48:52 pm »
That's sad to read, but I did appreciatte your effort about it, hope someone can make a windows editor, because I'm not capable of editing via Hex or codes, but I'm really interested into editing Contra...

Keep the good work man!   :thumbsup:

Grimlock

  • Sr. Member
  • ****
  • Posts: 361
  • Graphics Artist, Level Designer
    • View Profile
Re: New Tools for Red Falcon
« Reply #7 on: September 14, 2015, 12:06:39 am »
Being that Contra is one of Snarfblam's favorite NES titles I don't see how he could resist.  (He can literally beat the game without losing a single life).

I too would be interested in a Snarf Trax Contra editor.  Maybe I could edit the game into something I could actually beat (without thoroughly abusing save states).

TheLuigiLightning

  • Jr. Member
  • **
  • Posts: 37
  • ROM hacking; it's like rearranging classical music
    • View Profile
Re: New Tools for Red Falcon
« Reply #8 on: September 28, 2015, 05:23:56 pm »
Being that Contra is one of Snarfblam's favorite NES titles I don't see how he could resist.  (He can literally beat the game without losing a single life).

So?  I've beaten Contra without dying, and I've done it many, many times!  It's not really that impressive.
I am Luigi Lightning.  (You can just call me Luigi, though).
Some say my name is Luigi Lightning.  Others say I am a Lightning Luigi.  Some also say I am Luigi's Lightning.  Some even say I am some prodigy; The Luigi Lightning... guys, it's just a title.  You were correct the first time.

snarfblam

  • Submission Reviewer
  • Hero Member
  • *****
  • Posts: 590
  • CANT HACK METROID
    • View Profile
    • snarfblam
Re: New Tools for Red Falcon
« Reply #9 on: September 28, 2015, 05:47:49 pm »
You needn't be impressed. For people who didn't play it a lot as a kid, it's a much more difficult game. My brother saw me playing Trax's hack and was amazed I could dance through the bullets and move more than an inch without getting killed. Seems to me most people find it to be a very difficult game or a rather easy game, with little middle ground.

TheLuigiLightning

  • Jr. Member
  • **
  • Posts: 37
  • ROM hacking; it's like rearranging classical music
    • View Profile
Re: New Tools for Red Falcon
« Reply #10 on: September 28, 2015, 08:41:02 pm »
You needn't be impressed. For people who didn't play it a lot as a kid, it's a much more difficult game. My brother saw me playing Trax's hack and was amazed I could dance through the bullets and move more than an inch without getting killed. Seems to me most people find it to be a very difficult game or a rather easy game, with little middle ground.

Have you beaten Trax's hack with no continues yet?  (I have)
I am Luigi Lightning.  (You can just call me Luigi, though).
Some say my name is Luigi Lightning.  Others say I am a Lightning Luigi.  Some also say I am Luigi's Lightning.  Some even say I am some prodigy; The Luigi Lightning... guys, it's just a title.  You were correct the first time.

snarfblam

  • Submission Reviewer
  • Hero Member
  • *****
  • Posts: 590
  • CANT HACK METROID
    • View Profile
    • snarfblam
Re: New Tools for Red Falcon
« Reply #11 on: September 28, 2015, 09:25:30 pm »
I want to say yes, but it's been a while and I'm honestly not 100% sure whether or not I used any continues on my best run. My real goal is to have fun. ¯\_(ツ)_/¯

But congrats on your bullet dodging success  ;)

Grimlock

  • Sr. Member
  • ****
  • Posts: 361
  • Graphics Artist, Level Designer
    • View Profile
Re: New Tools for Red Falcon
« Reply #12 on: September 28, 2015, 10:28:12 pm »
For people who didn't play it a lot as a kid, it's a much more difficult game.

That's probably it.  I can beat Ghosts N Goblins without continuing, usually I make to to the castle on one life.  Most people find it to be an overly difficult game.  It's like riding a bike for me.

So?  I've beaten Contra without dying, and I've done it many, many times!  It's not really that impressive.
LOL, I was aiming for a degree of humor in my post, joking that Snarf couldn't resist.... nevermind  ::), impressidyness retracted.   :crazy:

TheLuigiLightning

  • Jr. Member
  • **
  • Posts: 37
  • ROM hacking; it's like rearranging classical music
    • View Profile
Re: New Tools for Red Falcon
« Reply #13 on: September 29, 2015, 04:40:53 pm »
That's probably it.  I can beat Ghosts N Goblins without continuing, usually I make to to the castle on one life.  Most people find it to be an overly difficult game.  It's like riding a bike for me.
LOL, I was aiming for a degree of humor in my post, joking that Snarf couldn't resist.... nevermind  ::), impressidyness retracted.   :crazy:

I'm sorry, I didn't mean to come off as a party pooper.  I just got a bit defensive about Contra, because I felt like you were giving a little too much praise to an individual over something that I could easily do.

As for Ghosts 'n Goblins... why... why would you get so good at that game...?  It's jam full of complete BS moments that are not challenge, but rather complete unfairness.  I'm still deciding on whether I want to even sit through the entire game... let alone twice...

September 29, 2015, 06:41:33 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
I want to say yes, but it's been a while and I'm honestly not 100% sure whether or not I used any continues on my best run. My real goal is to have fun. ¯\_(ツ)_/¯

But congrats on your bullet dodging success  ;)

We've really got to do a race through the game!  If you have Skype, I'll add you.
« Last Edit: September 29, 2015, 06:41:33 pm by TheLuigiLightning »
I am Luigi Lightning.  (You can just call me Luigi, though).
Some say my name is Luigi Lightning.  Others say I am a Lightning Luigi.  Some also say I am Luigi's Lightning.  Some even say I am some prodigy; The Luigi Lightning... guys, it's just a title.  You were correct the first time.