Finding shared code in NES games

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

Post Reply
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Finding shared code in NES games

Post by tepples »

In [url=https://forums.nesdev.com/viewtopic.php?p=217681#p217681]this post[/url], koitsu wrote:nobody at that time was making generic and free tools for making NES games. Nintendo probably would have sued them anyway
Let's drop the "and free" for a moment: Did Nintendo back then have a policy against authorized developers offering packaged engines or other middleware to other authorized developers? I doubt it. I know nowadays, a Unity license comes with the standard devkit.

It might be possible to tell whether middleware was used by comparing the binaries and compensating for anything that moved around, such as absolute or direct page addresses or parts that may have been ifdef'd out. In the past, I've suggested this as a way of demonstrating to the public that a modern-era platformer with all original code is not a hack of a commercial-era beat-em-up.

But it could also identify graphics engines that were adapted for use in a later game, such as Spiritual Warfare using a retooled version of the engine that Color Dreams had used for three prior Boulder Dash clones (I don't remember where I read this). And there are a couple known instances of cross-company middleware reuse during the classic era, such as Action 52 using a music engine developed by Sculptured Software, as kevtris discovered in 2011, which may have actually been licensed from Sculptured if Mario Gonzalez's recollection is anywhere near accurate. Likewise with Id licensing the engine of Wolfenstein 3D to Wisdom Tree.

There are also code snippets allegedly from the example programs that Nintendo provided to licensed developers, such as the following useless code in many licensed games that runs after palette updates:

Code: Select all

lda #$3F
sta $2006
lda #$00
sta $2006
sta $2006
sta $2006
Also some mysterious MMC3 init code, which I can't dig up at the moment through search.

It's been common throughout the modern era to reuse music engines, such as MUSE, FamiTone2, GGSound, and Pently. And with Shiru's neslib, cppchriscpp's nes-starter-kit, and NESmaker, modern-era NES middleware is set to take off.

There is a tool called nsfid to find shared audio drivers, but it takes manual definition of "signatures", as with antivirus, to identify these drivers. Might there be a tractable way to identify shared code across games in general?
User avatar
pubby
Posts: 583
Joined: Thu Mar 31, 2016 11:15 am

Re: Finding shared code in NES games

Post by pubby »

Tons of research went into this type of thing for DNA sequencing so that's probably a good place to start looking.

See for example Hirschberg's algorithm.

Ignoring all hardcoded addresses besides mapped registers sounds like a good plan.
NewRisingSun
Posts: 1510
Joined: Thu May 19, 2005 11:30 am

Re: Finding shared code in NES games

Post by NewRisingSun »

tepples wrote:There are also code snippets allegedly from the example programs that Nintendo provided to licensed developers
Is it attested that Nintendo actually provided any example code to licensed developers? My understanding is that all they got were badly-translated versions of the 2A03 and 2C02 datasheets (which we have in their Japanese originals) as well as the MMC1 and MMC3 data sheets.

Reused code snippets could also come from developers just disassembling the code from other games to learn from it, and in the case of obviously useless code, seems more likely to me.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Finding shared code in NES games

Post by psycopathicteen »

I've said this before. I think all Capcom SNES beat'm'ups and fighting games are hacks of Final Fight.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Finding shared code in NES games

Post by rainwarrior »

This reminds me a little of those computer analyses of old plays to decide which were written by Shakespeare in terms of their common content.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Finding shared code in NES games

Post by Oziphantom »

I think working out the blocks of code, then take the lowest address of the 'struct', then do deltas into the struct and compare based the code accessing Byte 7 of Something. Just taking the code and branches is probably not really going to be that useful, there are only so many ways to 'do a thing' on a machine as limited as the NES. you store meta tiles TL or Centre or BL and then have deltas, the delta code still looks the same. Minkowski collision and bounding box collision are going to be the same probably no matter who wrote it, there is the "this is the way to do it in the smallest number of clocks", there will be some variance. I've not looked at NES games much, but on the SNES you can really tell which programmer did which by changes in style, so that might help. It would also have to be matched against people changing jobs, i.e this person wrote this game at this company then moved to this one and "wrote" the same code at the new one ;)
I would be really surprised if the Ocean Developer Kit didn't also have NES stuff in it, however the ODK seems to have vanished into the either with only memories of it.
The UK game dev scene seems to be very lax, with developers showing off their stuff to other developers and sharing code and tools. Reading the History of Japanese Game development, its seems in Japan if you spoke to somebody from another company in Japan that was considered Treason, and grounds for instant dismissal.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Finding shared code in NES games

Post by rainwarrior »

Oziphantom wrote:The UK game dev scene seems to be very lax, with developers showing off their stuff to other developers and sharing code and tools. Reading the History of Japanese Game development, its seems in Japan if you spoke to somebody from another company in Japan that was considered Treason, and grounds for instant dismissal.
In relatively recent years I've seen some rather severe non-disclosure and non-compete clauses from major game companies in North America, and I've seen much more relaxed ones. Aside from the NDA stuff, a lot of them additionally specify that you're not allowed to participate in any game development activities (may also extend to related media like film/animation), even non-professional ones, outside of work (and if you do, they're automatically owned by them). The biggest predictor of severity seems to be the size of the parent company.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Finding shared code in NES games

Post by Oziphantom »

Sorry my tense was wrong.
Today 100% you share code you die, in the UK. Sony has the "any game dev you do out of work is ours too" clause. It's also kind of hard to share just a bit of C++, you usually need the whole thing or nothing at all. By the time you port the vector systems, code style, label names etc is it still the same code ;) Where as dropping in a bit of 6502 to do 'a thing' is a lot easier.

Back in the 80s, yes the companies still had the share code and die attitude, but well people got drunk in pubs a lot and even though they technically worked for different companies stuff got shared. I think the UK being so small helps. Basically the UK game scene is 2 degrees from anybody. Stealing also happened http://www.lemon64.com/forum/viewtopic.php?t=58990 also things like music production where often outsourced and the music drivers made by the musician - see https://commodoreformat.wordpress.com/t ... interview/ (search for SNES to get the relevant part) and there are quite a few sources for Jeroen Tel's audio engines floating around as he released them.

http://www.lemon64.com/?mainurl=http%3A ... 3FID%3D740 <-Reflective Designs
http://www.lemon64.com/?mainurl=http%3A ... 3FID%3D740 <-Reflective Designs

http://www.lemon64.com/?mainurl=http%3A ... 3FID%3D740 <- Genesis Software
Same engine ;) Same artist, different coder though...
User avatar
whicker
Posts: 228
Joined: Sun Dec 13, 2009 11:37 am
Location: Wisconsin

Re: Finding shared code in NES games

Post by whicker »

This whole conversation makes me sick to the stomach.
What positive unearthing can be produced by this endeavor?

Giving some old bag of bones copyright holder the idea and probable cause to sue 20-30 years after the fact?
Giving some up and coming coders a irreparable bad name because of alleged code theft?


As for the "any game dev you do out of work is ours too" clause, that has to do with the case that, yes, by default any creative work you do outside of work is by default yours. It's in there because they can put it in there, because we all fold over and comply when we need a job to support ourselves and family.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Finding shared code in NES games

Post by Oziphantom »

I believe the "all and any work you do out of 'work' is ours" clause is part of the "thou shall do overtime for no pay" aspect. In that if we are at work out of the nominal hours and not getting payed for it, then its technically "our work" and not "theirs", by stamping ownership on out "out of payed work" they get to keep all the work done on weekends and during crunch.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Finding shared code in NES games

Post by Oziphantom »

Maybe making a database of style traits is a good first step. So we can make something to identify the style of code, then find sections of code that break said style. I have a "make a nice pretty tree graph" script that analysts code and makes a code tree out of it. Making something like that then tags things with styles might make for a good starting point to show potential "borrowed" code.

Code: Select all

clc
lda Thing
adc Thing
vs

Code: Select all

lda Thing
clc
adc Thing
using Y more often the X first.
remembers that you can do

Code: Select all

ldx thing,y
rather than

Code: Select all

lda thing,y 
tax
counts up vs down
User avatar
whicker
Posts: 228
Joined: Sun Dec 13, 2009 11:37 am
Location: Wisconsin

Re: Finding shared code in NES games

Post by whicker »

psycopathicteen wrote:I've said this before. I think all Capcom SNES beat'm'ups and fighting games are hacks of Final Fight.
And all Mega Man games were copies of Mega Man games.

Capcom... where iteration is king.
User avatar
Gilbert
Posts: 564
Joined: Sun Dec 12, 2010 10:27 pm
Location: Hong Kong
Contact:

Re: Finding shared code in NES games

Post by Gilbert »

Also, calling these games hacks wouldn't be very appropriate, as Capcom itself published them, they're rather using the same "engine", and they're mostly arcade ports, that they did that when making the arcade originals anyway(as we all know, Capcom is very guilty on this, and also other companies, such as Konami), so when you port arcade games already using the same engine to a certain console, it's just natural to reuse (with updates, maybe) the same engine on that platform, other than starting from scratch for every single game.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Finding shared code in NES games

Post by Oziphantom »

this article mentions a few Middleware tools from back in the day https://gamehistory.org/aladdin-source-code/
Seem the Pro-Pack has a 65c02 and a 65816 version but not a 6502.. maybe the NES was too early for the market?
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Finding shared code in NES games

Post by tepples »

I'd assume so. By the so-called "16-bit era", Lynx and TG16 were already using 65C02 or customized versions thereof.
Post Reply