BBC Elite source, now fully documented and explained

reminisce about classic bbc micro and acorn electron games here
Related forum: adventures


User avatar
scarybeasts
Posts: 577
Joined: Tue Feb 06, 2018 7:44 am
Contact:

Re: BBC Elite source, now fully documented and explained

Post by scarybeasts » Tue Sep 01, 2020 11:35 pm

Great work Mark! The level of care, detail and quality put in here is spectacular.


Cheers
Chris

User avatar
MarkMoxon
Posts: 80
Joined: Thu Jul 18, 2019 4:38 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by MarkMoxon » Tue Sep 01, 2020 11:56 pm

Rich Talbot-Watkins wrote:
Tue Sep 01, 2020 4:42 pm
Wow, just had a chance to look at this! More detail there than I could possibly have imagined - great work! And nice to confirm that it really uses the Minsky hack for rotating things in place by small angles. Will look forward to browsing through this properly when I can!
I wouldn’t have known about Minsky if you hadn’t mentioned it in an older thread on this very site, Rich, so thanks for that! It’s a fascinating twist on the whole rotation story, and I’d have missed it otherwise. Makes you wonder what else I’ve accidentally glossed over. :shock:

Besides, there are definitely some rotation and circle-drawing routines in there that I don’t understand, so the investigations continue!

Mark

User avatar
oss003
Posts: 3399
Joined: Tue Jul 14, 2009 12:57 pm
Location: Netherlands
Contact:

Re: BBC Elite source, now fully documented and explained

Post by oss003 » Wed Sep 02, 2020 7:14 am

Nice work Mark .... very detailled info..... =D>

A few years ago I did the Atom conversion. Electron Elite was the base for this but there are still a few bugs in the Atom version. Maybe I can solve them now with your source because I did the conversion but didn't understand 80% of how the engine works.

http://www.retrosoftware.co.uk/wiki/ind ... omic_Elite

Greetings
Kees


User avatar
melchett
Posts: 317
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: BBC Elite source, now fully documented and explained

Post by melchett » Wed Sep 02, 2020 4:58 pm

Incredible achievement by all involved to make this available (and compile). Looking forward to the nights drawing in so I have an excuse to spend some quality time with this.

And just giving this a brief inspection now makes me even more in awe of what Angus Duggan did in the mid-90s with Elite-A.

Great work Mark for the deep dive commentary and organisation plus Kieran, Paul and Tom (I think those are variously responsible!) for the major stepping stones to get to there along the way. Wow.

One random observation from my skim through - interesting to see .BOMB used as a purchase indicator (&7F) and a state indicator (&FE or -2) to indicate tab being pressed and process it (ASLs .BOMB when Tab is pressed). Looking at Main flight loop (Part 5 of 16) there is a check that the current ship isn't a space station... wondering if I NOP that if it'll explode a space station... I think one of my childhood bucket list items might finally be ticked off if that works...

Code: Select all

 CPY #2*SST             \ If the ship in Y is the space station, jump to BA21
 BEQ MA21               \ as energy bombs are useless against space stations
Sadly I suspect it's more complex than that but roll on the weekend and I will see if I have time to try it.

cjpinder
Posts: 18
Joined: Fri Jul 03, 2020 6:00 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by cjpinder » Wed Sep 02, 2020 5:38 pm

MarkMoxon wrote:
Tue Sep 01, 2020 11:56 pm
I wouldn’t have known about Minsky if you hadn’t mentioned it in an older thread on this very site, Rich, so thanks for that! It’s a fascinating twist on the whole rotation story, and I’d have missed it otherwise. Makes you wonder what else I’ve accidentally glossed over. :shock:
I remember when I first converted that bit from 6502 to C, I thought it was a bug. :D It wasn't until sometime later that I read one of Jim Blinn's graphics articles where he discusses it and mentions Minsky. Having dug deeper since I've seen it in papers from the '70s describe it as a common bug which has a beneficial effect and also Ivan Sutherland used it and described it back in 1963 (9 years before Minsky) for his SKETCHPAD program.

Thanks,
Christian.

cjpinder
Posts: 18
Joined: Fri Jul 03, 2020 6:00 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by cjpinder » Wed Sep 02, 2020 5:41 pm

melchett wrote:
Wed Sep 02, 2020 4:58 pm
And just giving this a brief inspection now makes me even more in awe of what Angus Duggan did in the mid-90s with Elite-A.
Definitely! What Angus did was a superhuman feat in my opinion. :D

Thanks,
Christian.

User avatar
MarkMoxon
Posts: 80
Joined: Thu Jul 18, 2019 4:38 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by MarkMoxon » Wed Sep 02, 2020 7:03 pm

cjpinder wrote:
Wed Sep 02, 2020 5:41 pm
melchett wrote:
Wed Sep 02, 2020 4:58 pm
And just giving this a brief inspection now makes me even more in awe of what Angus Duggan did in the mid-90s with Elite-A.
Definitely! What Angus did was a superhuman feat in my opinion. :D
That is something we can all agree on! Elite-A is an absolutely amazing bit of work. I know I couldn’t have taken on this project without all the work previously done by others, but did he really just disassemble the raw code and work it all from there? That’s just astonishing...

Mark

cjpinder
Posts: 18
Joined: Fri Jul 03, 2020 6:00 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by cjpinder » Wed Sep 02, 2020 10:36 pm

MarkMoxon wrote:
Wed Sep 02, 2020 7:03 pm
..did he really just disassemble the raw code and work it all from there? That’s just astonishing...
Yes, just working on the disassembled code, and he used a disassembler and assembler ROM for the Beeb that he had written himself.

A lot of the assembler source code looks like this:

Code: Select all

l_340e
	STX $22
	STA $23
	LDA $40
	JSR square
	STA $9C
	LDA $1B
	STA $9B
	LDY #$BF
	LDA $28
	STA $26
	LDA $29
	STA $27
Even harder to figure out then the original Elite code. How he kept track of what each of the zero page locations was being used for without labelling them is beyond me. :o

Thanks,
Christian.

Kroc
Posts: 12
Joined: Sun Feb 17, 2013 12:24 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by Kroc » Wed Sep 02, 2020 11:12 pm

Wait, that's what I did for the C64 disassembly! I didn't want to use a RAM dump, as it would not be a clean representation of the original code, so I disassembled the disk image from scratch; fast-loader, packer, decrypter et al. This is why elite-harmless can assemble an original floppy disk, even with the several layers of indirection from the binary one would see in RAM. Thankfully, I did have the BBC sources to refer to, but it's been quite the slog.

cjpinder
Posts: 18
Joined: Fri Jul 03, 2020 6:00 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by cjpinder » Wed Sep 02, 2020 11:35 pm

Kroc wrote:
Wed Sep 02, 2020 11:12 pm
Wait, that's what I did for the C64 disassembly! I didn't want to use a RAM dump, as it would not be a clean representation of the original code, so I disassembled the disk image from scratch; fast-loader, packer, decrypter et al. This is why elite-harmless can assemble an original floppy disk, even with the several layers of indirection from the binary one would see in RAM. Thankfully, I did have the BBC sources to refer to, but it's been quite the slog.
I do appreciate what you've done is hard work, I've disassembled every version of Elite so I know what's involved. But even when I did Elite-TNK 20 years ago I had "modern" systems to help me. Angus was working on a BBC Model B, just a few years after Elite was released. There was no information out there on how Elite worked, not even much on how to do 3D. It was a big project to take on using a BBC micro.

Thanks,
Christian.

User avatar
MarkMoxon
Posts: 80
Joined: Thu Jul 18, 2019 4:38 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by MarkMoxon » Thu Sep 03, 2020 9:24 am

cjpinder wrote:
Wed Sep 02, 2020 11:35 pm
Angus was working on a BBC Model B, just a few years after Elite was released. There was no information out there on how Elite worked, not even much on how to do 3D. It was a big project to take on using a BBC micro.
What? He did it all on a BBC Micro? I didn't realise that. That's... just... well, that really is something else.
cjpinder wrote:
Wed Sep 02, 2020 10:36 pm
A lot of the assembler source code looks like this:

Code: Select all

l_340e
	STX $22
	STA $23
	LDA $40
	JSR square
	STA $9C
	LDA $1B
	STA $9B
	LDY #$BF
	LDA $28
	STA $26
	LDA $29
	STA $27
Even harder to figure out then the original Elite code. How he kept track of what each of the zero page locations was being used for without labelling them is beyond me. :o
Some people just manage to think like that, I guess. I remember when I was at university, we had a small but regular gathering of like-minded Acorn users, and we'd show each other what we were working on. One of the regulars was Dominic Symes, who went on to work for ARM. He'd started writing a super-fast text editor for RISC OS called Zap (it's still available, though he passed on the code years ago). When he showed us the source code, all his ARM assembler label and variable names were things like Zz and a8 and stuff like that. It was completely indecipherable, though Zap ended up being the most amazing editor, so it clearly worked for him. (The code was presumably rewritten by others in the intervening years, as it's pretty clean now.)

Then again, I guess in the days of the BBC Micro, a lot of documentation would be done on a notepad by the side of the computer, so presumably Angus wrote down what all the zero-page locations meant. Still, working out what they all meant must have taken some time, particularly the denser flags where one bit does this, another bit does this and so on. That's real dedication.

(To be honest, I feel the same way about anyone who can disassemble from scratch to that level, so respect to both of you, Christian and Kroc. You're clearly on top of your game!)
cjpinder wrote:
Wed Sep 02, 2020 10:36 pm
MarkMoxon wrote:
Wed Sep 02, 2020 7:03 pm
..did he really just disassemble the raw code and work it all from there? That’s just astonishing...
Yes, just working on the disassembled code, and he used a disassembler and assembler ROM for the Beeb that he had written himself.
Well, that's just showing off. ;-)

Mark

User avatar
melchett
Posts: 317
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: BBC Elite source, now fully documented and explained

Post by melchett » Thu Sep 03, 2020 10:57 am

melchett wrote:
Wed Sep 02, 2020 4:58 pm
Sadly I suspect it's more complex than that but roll on the weekend and I will see if I have time to try it.
Turns out it really was that simple and so immensely satisfying...

https://www.youtube.com/watch?v=YDZNLbzOn1w

Disk file attached if you want to try it yourself...
Attachments
elite.ssd
(26.5 KiB) Downloaded 10 times

User avatar
MarkMoxon
Posts: 80
Joined: Thu Jul 18, 2019 4:38 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by MarkMoxon » Thu Sep 03, 2020 11:34 am

melchett wrote:
Thu Sep 03, 2020 10:57 am
melchett wrote:
Wed Sep 02, 2020 4:58 pm
Sadly I suspect it's more complex than that but roll on the weekend and I will see if I have time to try it.
Turns out it really was that simple and so immensely satisfying...

https://www.youtube.com/watch?v=YDZNLbzOn1w

Disk file attached if you want to try it yourself...
Ha! That is absolutely epic! =D>

It always amazes me how just one instruction can make such a difference. That's one of the things I loved about documenting the source, when a lone instruction, possibly just 8 bits, would earn itself paragraphs of explanation.

I mean, destroying an entire space station by changing one branch instruction? That's like discovering that the thermal exhaust port leads to the main reactor core. Mwuhahahahaha! :twisted:

Mark

User avatar
scarybeasts
Posts: 577
Joined: Tue Feb 06, 2018 7:44 am
Contact:

Re: BBC Elite source, now fully documented and explained

Post by scarybeasts » Thu Sep 03, 2020 6:44 pm

MarkMoxon wrote:
Sun Aug 30, 2020 3:11 pm
I don't think Elite has been analysed to this extent before, and it's been fascinating to explore the source code in this level of detail. Not only is every single bit (literally!) documented in full,
Have you looked at code differences between different Elite variants?

I just posted a thread to discuss bug fixes and changes applied to the original release, including disc images for the variants we've found so far.
viewtopic.php?f=1&t=20410

I wonder which variant your disassembly is based on?


Cheers
Chris

User avatar
MarkMoxon
Posts: 80
Joined: Thu Jul 18, 2019 4:38 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by MarkMoxon » Thu Sep 03, 2020 7:23 pm

scarybeasts wrote:
Thu Sep 03, 2020 6:44 pm
MarkMoxon wrote:
Sun Aug 30, 2020 3:11 pm
I don't think Elite has been analysed to this extent before, and it's been fascinating to explore the source code in this level of detail. Not only is every single bit (literally!) documented in full,
Have you looked at code differences between different Elite variants?

I just posted a thread to discuss bug fixes and changes applied to the original release, including disc images for the variants we've found so far.
viewtopic.php?f=1&t=20410

I wonder which variant your disassembly is based on?
The version I've looked at is the tape version source from Ian Bell's site - I don't know how many variants there are of the tape version? I'm hoping to document the extra code in the disc and second processor versions at some point, too - that should be interesting. But I'm going to add some polish to the tape analysis first, as it's still a bit rough round the edges.

I'm also planning to compare the version I've documented to the version on my tape version of the game, just to see if the binaries really do match, as that would be interesting to see!

Mark

dominicbeesley
Posts: 1211
Joined: Tue Apr 30, 2013 12:16 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by dominicbeesley » Fri Sep 04, 2020 10:43 am

How different are the tape / disk variants? Is it likely possible to get them into a single source with IF/DEFs to build the variants or are they just too different - I speak from a position of ignorance, I don't really know the differences that well but I'd like to do some hacking...

D

User avatar
MarkMoxon
Posts: 80
Joined: Thu Jul 18, 2019 4:38 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by MarkMoxon » Fri Sep 04, 2020 11:00 am

dominicbeesley wrote:
Fri Sep 04, 2020 10:43 am
How different are the tape / disk variants? Is it likely possible to get them into a single source with IF/DEFs to build the variants or are they just too different - I speak from a position of ignorance, I don't really know the differences that well but I'd like to do some hacking...
From memory, there are quite a lot of cool extras in the disk version that aren't in the tape version:
  • A load more ship types
  • Two types of station
  • Mining and military lasers
  • Two missions
  • A proper docking computer
  • You can search for systems by name
  • Bitstick support
The rest of the game is identical to the tape version (though that doesn't mean the code is identical). The disk version is split up into two separate programs, one that runs when you're docked, and the other that runs when you're in space. The tape version is just one program.

So they are very different, but also very similar.

Mark

cjpinder
Posts: 18
Joined: Fri Jul 03, 2020 6:00 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by cjpinder » Fri Sep 04, 2020 12:06 pm

dominicbeesley wrote:
Fri Sep 04, 2020 10:43 am
How different are the tape / disk variants? Is it likely possible to get them into a single source with IF/DEFs to build the variants or are they just too different - I speak from a position of ignorance, I don't really know the differences that well but I'd like to do some hacking...
It would be best to use the 2nd Pro Elite sources as it is basically the disk version of Elite combined into one executable, rather than the two separate executables that Disk Elite is (one while docked, the other while in flight).

Thanks,
Christian.

Kroc
Posts: 12
Joined: Sun Feb 17, 2013 12:24 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by Kroc » Fri Sep 04, 2020 1:02 pm

I've just discovered a bug in the Commodore 64 port. Attempting to enable the docking computers does a check to see if the station is hostile: (BBC Code)

Code: Select all

 LDA K%+NI%+32          \ Fetch the AI counter (byte #32) of the second ship
 BMI MA68               \ from the ship data workspace at K%, which is reserved
                        \ for the sun or the space station (in this case it's
                        \ the latter), and if it's negative, meaning the
                        \ station is hostile, jump down to MA68 to skip the
                        \ following (so we can't use the docking computer to
                        \ dock at a station that has turned against us)
On the Commodore 64, it happens that the wrong label/address was perhaps used:

Code: Select all

        ; turn docking computer on?
        ;-----------------------------------------------------------------------
:       lda key_docking_on      ; key for docking computer pressed?     ;$1FC2
        and PLAYER_DOCKCOM      ; does the player have a docking computer?
       .bze :+                  ; no, skip

.ifdef  OPTION_ORIGINAL
        ;///////////////////////////////////////////////////////////////////////
        eor joy_down            ; combine with down key state???        ;=$8D35
.else   ;///////////////////////////////////////////////////////////////////////
        eor polyobj_01+PolyObject::attack                               ;=$F945
.endif  ;///////////////////////////////////////////////////////////////////////
       .bze :+

        sta DOCKCOM_STATE       ; turn docking computer on (A = $FF)
        jsr _9204               ; play docking computer music
Unless I'm misunderstanding the purpose of this check, the game combines the key-down state ($00=unpressed, $FF=pressed) with the key state for the docking computers ("C") -- I can't think of any logical reason why that would otherwise be relevant! Just thought this would be interesting to pass on.

EDIT: Just tested and can confirm, you can't enable docking computers, if holding the joystick/key for down!

User avatar
MarkMoxon
Posts: 80
Joined: Thu Jul 18, 2019 4:38 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by MarkMoxon » Fri Sep 04, 2020 1:08 pm

Kroc wrote:
Fri Sep 04, 2020 1:02 pm
I've just discovered a bug in the Commodore 64 port.
First thing that springs to mind is that in the tape version of BBC Elite, you dock instantly as soon as you hit the "C" key. The disk version implements the full computer experience where it steers the ship for you (though no Blue Danube, unfortunately!), but in the tape version, pressing "C" jumps you straight to the docking tunnel.

Would this be a reason for the EOR with joy_down in the C64 version? Perhaps you can break out of the docking computer by moving the joystick, something that wouldn't make sense in the insta-dock of the tape version?

Mark

dominicbeesley
Posts: 1211
Joined: Tue Apr 30, 2013 12:16 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by dominicbeesley » Fri Sep 04, 2020 1:14 pm

Thanks both,

I'll try and get a look at this in the next week or so - I'll probably stick with the tape version for my initial experiments but I'm hoping to get the Blitter's line drawing acceleration poked in - it looks like it _should_ be straightforward as the line drawing code is pretty clear, at least on first inspection.

How well does the buildable source deal with changes? Do I need to pad out to exactly the same size for the code or should all the tables/labels sort themselves out?

D

Kroc
Posts: 12
Joined: Sun Feb 17, 2013 12:24 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by Kroc » Fri Sep 04, 2020 1:21 pm

MarkMoxon wrote:
Fri Sep 04, 2020 1:08 pm
First thing that springs to mind is that in the tape version of BBC Elite, you dock instantly as soon as you hit the "C" key. The disk version implements the full computer experience where it steers the ship for you (though no Blue Danube, unfortunately!), but in the tape version, pressing "C" jumps you straight to the docking tunnel.

Would this be a reason for the EOR with joy_down in the C64 version? Perhaps you can break out of the docking computer by moving the joystick, something that wouldn't make sense in the insta-dock of the tape version?
I'm not sure what the intention (or outcome) of the EOR is; given that it's only checked when "C" is held, so it can't be for the purposes of breaking docking computer control because that wouldn't make sense only for one direction (any direction should cancel, if this is the intention). It may be that the order of keys in the key-table is implying something else from the BBC's perspective, and they didn't correct it; `joy_down` is the "X" key, and this happens to appear 3 bytes before "C" in the key table on the C64. I would be interested to know what the BBC disk version is checking against...

EDIT: I checked Brink's disk disassembly, and it looks like there's no additional check!

Code: Select all

	.MA64	\ check dock C key
AD 0F 03                LDA &030F \ KL+15  \ key 'C' docking computer
2D 84 03                AND &0384 \ DKCMP  \ have a docking computer?
F0 03                   BEQ MA68	   \ onto Laser
8D 3F 03                STA &033F \ DAUTO  \ auto docking set
	.MA68	\ onto Laser
This is curious as to what the C64 is trying to do!

User avatar
MarkMoxon
Posts: 80
Joined: Thu Jul 18, 2019 4:38 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by MarkMoxon » Fri Sep 04, 2020 1:30 pm

dominicbeesley wrote:
Fri Sep 04, 2020 1:14 pm
Thanks both,

How well does the buildable source deal with changes? Do I need to pad out to exactly the same size for the code or should all the tables/labels sort themselves out?
I've always had to pad out the code, and it seems pretty fussy if you don't. I haven't looked into what's causing that, but there could be tables near to page boundaries, that sort of thing. I'd definitely build it with:

Code: Select all

make build
if making changes to the code, to disable all the checksum stuff.

Mark

User avatar
MarkMoxon
Posts: 80
Joined: Thu Jul 18, 2019 4:38 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by MarkMoxon » Fri Sep 04, 2020 1:43 pm

Kroc wrote:
Fri Sep 04, 2020 1:21 pm
This is curious as to what the C64 is trying to do!
Given that the C key is right next to the X key on the keyboard, is this check preventing the docking computer from kicking in when you're trying to pitch down with X, but accidentally push the C key down as well?

Mark

Kroc
Posts: 12
Joined: Sun Feb 17, 2013 12:24 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by Kroc » Fri Sep 04, 2020 1:46 pm

Oh wow, that's insightful! That's a real good catch

User avatar
MarkMoxon
Posts: 80
Joined: Thu Jul 18, 2019 4:38 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by MarkMoxon » Fri Sep 04, 2020 1:49 pm

Kroc wrote:
Fri Sep 04, 2020 1:46 pm
Oh wow, that's insightful! That's a real good catch
Sign of a misspent youth, endlessly playing Elite. :-)

Mark

User avatar
melchett
Posts: 317
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: BBC Elite source, now fully documented and explained

Post by melchett » Fri Sep 04, 2020 6:27 pm

MarkMoxon wrote:
Thu Sep 03, 2020 11:34 am
Ha! That is absolutely epic! =D>
I updated this so you could destroy it with lasers too not just an energy bomb Mark... interesting that the code auto re-spawns a space station after the explosions complete. I could also add in a load of containers when it explodes... maybe later tonight.

Elite.ssd

Kroc
Posts: 12
Joined: Sun Feb 17, 2013 12:24 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by Kroc » Fri Sep 04, 2020 6:37 pm

Is everybody aware of Elite-B? http://aegidian.org/bb/viewtopic.php?f=7&t=16899 It's another highly-improved version of BBC Elite, but this time done from the original HIBASIC sources IFIRC.

User avatar
Diminished
Posts: 566
Joined: Fri Dec 08, 2017 9:47 pm
Contact:

Re: BBC Elite source, now fully documented and explained

Post by Diminished » Fri Sep 04, 2020 9:26 pm

MarkMoxon wrote:
Fri Sep 04, 2020 11:00 am
  • Bitstick support
Huh. This I didn't know.

Has anyone ever looked at the NES port? ISTR Ian Bell saying that was his favourite 8-bit version, since they had to work out a way of drawing vectors using the console's tile-based graphics system.

Post Reply

Return to “8-bit acorn software: classic games”