Documented and annotated source code for Elite on the Commodore 64
188 points
5 days ago
| 8 comments
| github.com
| HN
mgkimsal
1 day ago
[-]
Very curious how Mark Moxon was able to understand and comment so much of the code. Just... a very big fan with a lot of free time?

No idea how this will be formatted, but the level of understanding in the comments is quite deep for just having access to the original source. Or did the original source have this level of comments as well?

How long does a project like this take to comment?

.QQ22 SKIP 2 ; The two hyperspace countdown counters ; ; Before a hyperspace jump, both QQ22 and QQ22+1 are ; set to 15 ; ; QQ22 is an internal counter that counts down by 1 ; each time TT102 is called, which happens every ; iteration of the main game loop. When it reaches ; zero, the on-screen counter in QQ22+1 gets ; decremented, and QQ22 gets set to 5 and the countdown ; continues (so the first tick of the hyperspace counter ; takes 15 iterations to happen, but subsequent ticks ; take 5 iterations each) ; ; QQ22+1 contains the number that’s shown on-screen ; during the countdown. It counts down from 15 to 1, and ; when it hits 0, the hyperspace engines kick in

reply
MarkMoxon
1 day ago
[-]
This should answer your question:

https://elite.bbcelite.com/about_site/about_this_project.htm...

Some parts of Elite were documented prior to my project, particularly the procedural generation and ship data blocks. But none of it was documented to this level; it's taken time, lots of it!

I love this game, and I figured it deserved a proper homage. Or, to put it another way, this is a labour of love. :-)

reply
WillAdams
1 day ago
[-]
Have you considered turning this into a book?

If you used Literate Programming principles:

http://literateprogramming.com/

then it could become a seamless narrative which could be very expressive.

reply
MarkMoxon
1 day ago
[-]
Yeah, it's a bit tricky when the code you are documenting is copyright, and you aren't the copyright owner. Website is one thing, but publishing a book? I suspect that is asking for trouble.

Also, books can't be updated, and I update this stuff all the time...

reply
0xDEADFED5
1 day ago
[-]
I've never owned a C64 or played Elite, but the dedication shown to your hobby is inspiring, thanks for the effort, it's very cool.
reply
MarkMoxon
1 day ago
[-]
Thank you! I came at it from the BBC Micro angle, which was the system I grew up with, and I have to say that analysing Elite been a brilliant way to learn about other 8-bit platforms. I’ve documented the NES version and now the Commodore 64, and the Apple II is next.

It’s the retro equivalent of discovering that if you like the Beatles, you’ll probably like the Stones, The Who and Pink Floyd. :-)

reply
WillAdams
1 day ago
[-]
Maybe just make a PDF and publish that to the site?

I am doing that at:

https://github.com/WillAdams/gcodepreview/blob/main/gcodepre...

(but admittedly it's a very different project and no copyright complexities)

reply
MarkMoxon
1 day ago
[-]
Honestly, for me personally and on this specific project with its specific history of copyright issues (look it up!), that would be crossing the line into disrespecting the copyright situation.

Websites are ethereal, in a sense, as they are easy to switch off and hard to copy and distribute. PDFs and books are the opposite. Sure, websites get archived and repos get forked, but I think PDFs and books fall into a different area.

I run these projects very cautiously and very carefully. I don't think publishing a book or PDF containing copyright material is a good idea in this instance, to be honest!

reply
hathawsh
1 day ago
[-]
You don't need to be the copyright owner. All you need is a license from the copyright owner. It can't hurt to contact Ian Bell and see what you can negotiate. http://www.iancgbell.clara.net/

Edit: never mind, it sounds like Ian sold his copyright and now there's a mess. Hmm. https://arstechnica.com/gaming/2017/03/elite-dangerous-crowd...

reply
MarkMoxon
1 day ago
[-]
Well, exactly. This project is a hobby, and I’d like to try to keep it as my happy place!

Besides, I’ve published PDFs of my travel writing sites, and the thought of trying to keep a code repository, a website and a PDF in sync fills me with dread…

reply
hathawsh
1 day ago
[-]
Good for you! Keep it simple.
reply
jlarcombe
8 hours ago
[-]
Interesting that, Chris Jordan was part of Acornsoft when the original game was being developed and is also well known for his Hybrid Music System for the BBC Micro, way ahead of its time.
reply
kstrauser
1 day ago
[-]
I understand and respect your opinion there. In the spectrum of copyright violation, I might be willing to let my kid install a copy of a game I bought on their own computer, but I would definitely not sell copies of it.

But it’s a massive bummer to me that copyright is preventing someone from publishing their research on a 40 year old game that hasn’t been available for sale in decades. I don’t know exactly where that lands on my moral spectrum, but I put it far closer to the left than to the right, legalities aside.

reply
WillAdams
1 day ago
[-]
Cogent points.

If you are able to get permission for a game code and then do this sort of analysis as a Literate Program and publish that as a book, you'd be in rather rarified company, and I'd certainly buy a copy.

reply
mgkimsal
11 hours ago
[-]
Thank you for your service! ;)

Seriously, thanks for the details. This was a bit of a pivotal game for me in ... '86 IIRC. It's been interesting to see so much of a following over the decades. Just confirms that whatever was intriguing to me connected with so many other people too!

reply
anyfoo
1 day ago
[-]
The comments you pasted in particular are about stuff that makes sense and that someone who wants to fully understand some source code can readily figure out, if they put their mind to it.

It's when things don't make sense that it gets interesting, because then you have to guess the original author's intentions, suspect a bug, question your understanding, or deal with other uncertainties. That's usually when a bunch of question marks start to appear in reverse engineering comments (e.g. "increment xyz???")...

reply
MarkMoxon
1 day ago
[-]
I keep a list of everything that isn’t 100% clear in my commentary, here:

https://elite.bbcelite.com/about_site/to-do_list.html

This is not a big list, and these are all pretty subtle aspects of the game. After 4 years of analysis, I think we’re pretty close to understanding pretty much everything, which is nice.

reply
robertlagrant
1 day ago
[-]
I loved Elite on the BBC B as a kid. It was before my time, but we had inexpensive tastes in our personal computing growing up. I absolutely loved it, and I can definitely understand someone spending this much time on it.
reply
Koshcheiushko
1 day ago
[-]
This is really good resource for someone, who wants to learn assembly.

Can somebody please share this good or closer documented source code in other languages such as C++, C or any other.

reply
MarkMoxon
1 day ago
[-]
The original Elite was reverse-engineered into C by Christian Pinder as part of the Elite: The New Kind project. The source is out there. It's a brilliant bit of work.

You can use a search engine to find it.

reply
WillAdams
1 day ago
[-]
That would be the domain of "Literate Programming":

http://literateprogramming.com/

esp. see:

http://literateprogramming.com/adventure.pdf

reply
mcraiha
1 day ago
[-]
Maybe someone can now fix the following bug? "if you started the auto-dock on the wrong side of the station, it would crash into it instead"
reply
taneliv
1 day ago
[-]
Is it perhaps as easy as adding the check on https://github.com/markmoxon/elite-source-code-commodore-64/... ?
reply
MarkMoxon
1 day ago
[-]
Unfortunately it isn't that simple. Check 3 only looks to see if we are moving backwards into the station slot. This is a bit pointless to calculate as falling backwards would mean that a number of the other checks (e.g. angle of approach) will already be failing.

This is why check 3 is omitted from later versions of Elite, including the C64 version; it isn't needed.

Lots of information on the docking checks here:

https://elite.bbcelite.com/deep_dives/docking_checks.html

Besides, is this a bug or a feature? Elite lore says that machine intelligence is banned in the galaxy, so I like to think of this as fitting in with that. Docking computers can kill you in Elite - and it's the same in Elite Dangerous. :-)

reply
voidUpdate
1 day ago
[-]
Pretty much the first time I ever tried to dock, the docking computer set me down squarely on top of another player's ship. After trying my best to cancel the docking, I ended up losing my docking request, which meant I wasn't allowed to be there, and got the space police after me. I've not really played it much since
reply
MarkMoxon
1 day ago
[-]
Yup. "Never fly without a rebuy", as they say!
reply
teddyh
1 day ago
[-]
You aren’t allowed to make any changes.

Under GitHub's rules, you have the right to read and fork this repository... but that's it. No other use is permitted, I'm afraid.

— README.md

reply
_flux
1 day ago
[-]
It seems though the person who did this repo already violated the copyright by adding these annotations to the source code, correct?

It wouldn't be a reason or validation for others doing the same, of course.

However, whatever one would choose to do, it's best not to do it in GitHub..

reply
jfim
1 day ago
[-]
The creator of the repository does mention it:

> My hope is that the educational and non-profit intentions of this repository will enable it to stay hosted and available, but the original copyright holders do have the right to ask for it to be taken down, in which case I will comply without hesitation. I do hope, though, that along with the various other disassemblies and commentaries of this source, it will remain viable.

reply
glimshe
1 day ago
[-]
Long copyrights are a cancer in our society. Just notice the fear in his writing - "without hesitation". We're talking about a ~40 year piece of work here.

Patents last 20 years and people keep filing them in the millions. We remain an inventive species. Obviously the protection works. Why do we need to protect copyrights for near a century?

reply
MarkMoxon
1 day ago
[-]
That's not fear, it's an indication of the respect in which I hold the original authors (whom I believe are still the copyright holders). If Bell or Braben asked me to take it this down, I'd roll with it. Same if Geoff Crammond asked me to take down my Aviator and Revs analyses; of course I'd comply. It's their code.

I have copyright content out there in the world (including the commentary aspects of this project), and I'd want to be able to control what happens to that too. Seems fair to me.

reply
glimshe
1 day ago
[-]
I admire your integrity. At the same time, these "rights" come from flawed laws. The code should no longer be "theirs".

I won't write a long and boring critique of the current copyright length, but this work should be in the public domain at this point - nobody should be entitled to ask you to take it down. It should belong to you as much as it does to them. Like Algebra and Hamlet.

It in fact belongs to humanity, as the creation of the work itself was built on top of everything that came before it.

reply
danielbln
1 day ago
[-]
Two reasons: lobbying and the Mouse.
reply
ddingus
1 day ago
[-]
The Mouse has not come back for a third round. Yet.
reply
Pannoniae
1 day ago
[-]
That is true, but that doesn't mean that someone can't do it anyway. Copyright is a right, not an obligation (unlike trademarks where enforcement is required to preserve the trademark)

If someone makes a patch and publishes it, the rightsholders do have a case against whoever published it, but that requires enforcement in the form of a C&D or a lawsuit. The rightsholder might very well decide to not do anything about it, which happens fairly commonly.

This is not a substantial barrier for making a patch like that.

reply
tialaramex
1 day ago
[-]
> unlike trademarks where enforcement is required to preserve the trademark

That's a myth. It suits trademark lawyers and aggressive owners to pretend this is obligatory but it isn't.

reply
teddyh
1 day ago
[-]
reply
tialaramex
1 day ago
[-]
Yes, genericization is not actually a risk that aggressive lawyers can help you with, except in the sense that if they bankrupt you now it's not a problem any more.

Genericization occurs when more or less everybody uses your word mark instead of a generic product class. But you can't actually sue everybody. And if you chase say, popular media, it just becomes a joke - Stephen Colbert can't use the word literally everybody you know uses because his bosses will get sued, ha ha, but it doesn't stop you and it won't stop genericization from happening. Notice you won't find any courts checking that you spent enough on legal fees as otherwise you lose for inadequate enforcement. They only care that ordinary people, who you wouldn't sue anyway, used this word in a generic way.

Beyond that, it's not at all obvious that this is a problem you'd want to prevent. Why are Kleenex and Xerox so well known? It's surely not because they're unsuccessful!

reply
another2another
1 day ago
[-]
Well that is some well documented code, and no mistake.

It keeps mentioning a Cougar ship type, but I don't remember them in the game?

reply
MarkMoxon
1 day ago
[-]
It is in-game, but it is astonishingly rare. Specifically, there is a 0.011% chance of spawning a Cougar during each ship spawning routine, which is around 1 in 9000 ship spawnings

And it's got a cloaking device so it doesn't appear on your scanner.

Anyone who has genuinely seen one of these in-game is a really lucky commander!

Lots of details here:

https://elite.bbcelite.com/deep_dives/the_elusive_cougar.htm...

reply
another2another
1 day ago
[-]
Hmm, I wonder if that's what the second mission was to find?

I played it on the CBM64, and seem to remember being given a mission to find a stealth ship. Flew around loads, but never found it as far as I can remember.

reply
MarkMoxon
1 day ago
[-]
No, the Cougar is nothing to do with missions (in the 6502 versions, anyway - the other platforms have different mission code). It's just a rarely called part of the random spawning routine. Very rarely called.

The mission-related ship is the Constrictor, which you only bump into at the end of that mission.

Obligatory link: https://elite.bbcelite.com/deep_dives/the_constrictor_missio...

reply
lyu07282
1 day ago
[-]
YouTube video/documentary about the game:

"The game that couldn't be written" - https://youtu.be/lC4YLMLar5I

reply
qsi
1 day ago
[-]
Just scanned some files and I see a lot of NOPs, sometimes a few consecutively. Any idea why?
reply
MarkMoxon
1 day ago
[-]
All NOPs should be explained in the commentary, apart from the ones in the fast loader routine in the elite-gma1.asm file. Are these the ones you mean?

If so, I haven't documented the fast loader as it's not really a feature of Elite, but I think the NOPs there are for timing when talking to the CIA1. The fast loader is documented in the Elite Harmless project, here, which might help:

https://github.com/Kroc/elite-harmless/blob/kroc/src/boot/gm...

The long string of NOPs in the elite-firebird.asm source are padding to ensure the vector overrides align with the correct addresses, as described in the commentary.

Most other NOPs are commenting out the checksums if that feature is disabled by the build; again, they should be explained in situ.

If you're wondering about any others, I'd be happy to explain!

reply
FrustratedMonky
1 day ago
[-]
Has anybody done something similar, but converted to a modern language?
reply
astrobe_
1 day ago
[-]
Oolite [1] is implemented in Objective-C and scripted in Javascript. The "strict mode" base game has the look'n'feel of the original - there's even an option for wireframe display somewhere - but its vast ecosystem of mods (500+ last time I played, some years ago) is much more interesting.

I don't play it anymore because I'm more interested in building games and game building now (with Luanti [2]), but it is IMO one of the top FOSS titles.

[1] https://oolite.space/ [2] https://www.luanti.org/

reply
MarkMoxon
1 day ago
[-]
Yes. The original Elite was reverse-engineered into C by Christian Pinder as part of the Elite: The New Kind project. The source is out there. It's a brilliant bit of work.
reply
Lerc
1 day ago
[-]
Would you have any objection to your version being used as an AI test?

It seems plausible that AIs could port this code to other architecures. It seems like a good large scale task that most systems probably can't manage right now, but perhaps soon.

reply
tialaramex
1 day ago
[-]
Although C probably counted as a modern language back then (after all it's not B) today I think "modern" probably means at least Java and likely something from this century like Rust or Typescript.
reply
MarkMoxon
1 day ago
[-]
Oolite is normally quoted at this point. I think it's in Objective C? But exactly how much it relates to the original game's code, I don't know.

https://github.com/OoliteProject/oolite

reply
FrustratedMonky
1 day ago
[-]
anything would be great.

Oolite does look like Mac, done in COCO? Even Mac/Coco looks dated. Not the screens, they actual look is great.

A Rust version would be cool.

reply
astrobe_
1 day ago
[-]
"Modern" means "we fixed the deficiencies of the old project and introduced our own". When I read "modern" I understand it's likely to be a variation of the second system effect [1]. When it's not just advertisement/PR BS.

When it's part of a request, it generally means "I don't know tech XYZ but I'm pretty sure I could enjoy it and contribute if it was using a tech I know". Which is generally a form of procrastination.

I dislike Javascript and I don't know Objective-C, and it didn't prevent me to tinker with Oolite, which uses both, because I like the game (now, tbh assembly is "hardcore" so OP's request is legitimate).

[1] https://www.joelonsoftware.com/2000/04/06/things-you-should-...

reply
cptnapalm
1 day ago
[-]
Note: there's a crash bug. If you try to look at the local sun, the game will try to explode it, but suns can't explode so the game crashes.
reply