Level 9 Version 1 Assembly + Python Interpreter

discuss classic text/graphic adventures for the bbc micro & electron
Post Reply
melchett
Posts: 478
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Level 9 Version 1 Assembly + Python Interpreter

Post by melchett »

I published today the Level 9 Version 1 Python Interpreter that I have been working on. It's been a fascinating journey reverse engineeing and understanding what the Austin brothers put together all those years ago.

BBC Micro Assembly

The engine itself is pretty simple when implemented in modern languages but I also disassembled and commented the original v1 engines for the following games. They all more or less share a common engine (more on that later).

* Adventure Quest
* Colossal Aventure
* Dungeon Adventure
* Lords of Time
* Snowball

Those are the specifics to the games e.g. data + main wrapper. The actual engine can be found here

The following may be useful references when understand the BBC Micro Version code:

* BBC Micro Zero Page Variable Usage
* BBC Micro Level 9 Common Engine
* Level 9 Version 1 A-Code Specification
* BBC Micro Compiler Memory Locations

There is a more guidance on how to compile the BBC Micro Assembly here

https://github.com/ajgbarnes/level9

I captured all my notes (excuse any typos, I'll slowly improve that over time) here:

https://github.com/ajgbarnes/level9/blo ... ication.md

Python Interpreter

Details on how to run the Level 9 Version 1 Python Interpreter can be found here:

https://github.com/ajgbarnes/level9

The source code is commented by I probably need to improve it here:

https://github.com/ajgbarnes/level9/blob/main/level9.py

It's a multi-functional interpreter - it can dump the dictionary, the game descriptions/messages and also play the games either manually or via script files.

A-Code Decompilation

The power of what they created back in the early 80s can be seen when you look at the A-Code decompilations (decompiler is bundled with the python interpreter above, not so well commented). There is so much code optimised to a few bytes per command/list handler.

https://github.com/ajgbarnes/level9/tre ... ompilation

Hope this is useful and educational distraction for you on a Sunday afternoon. This took far longer than I anticipated.

Edit: Not sure if I should have posted here or somewhere else. Normally cross-posting is frowned upon so I kept it here. Appreciate any feedback from you all.
Last edited by melchett on Sun Jan 22, 2023 8:29 pm, edited 2 times in total.
User avatar
lurkio
Posts: 4351
Joined: Wed Apr 10, 2013 12:30 am
Location: Doomawangara
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by lurkio »

Good Lord! I’ve only just seen this, and I haven’t begun to digest any of it yet, but at first glance it looks absolutely monumental! Well done! Amazing work!

=D> =D> =D>

Of course, you know that the next step is for you to make an adventure creator utility that compiles a user-friendly adventure language down to A-code..! (A sort of “Quill for A-code”!)

:wink:
nicolagiacobbe
Posts: 215
Joined: Tue Jul 03, 2007 10:40 am
Location: italy
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by nicolagiacobbe »

Really wonderful.
A small question arises: does the virtual machine code permits graphics? Apart from using the VDU drivers I mean, a virtual machine could enable a much tighter graphics code than the simple VDU.
melchett
Posts: 478
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by melchett »

nicolagiacobbe wrote: Sun Jan 22, 2023 4:30 pm Really wonderful.
A small question arises: does the virtual machine code permits graphics? Apart from using the VDU drivers I mean, a virtual machine could enable a much tighter graphics code than the simple VDU.
Great question - yes it does but I cannot see that in any of the version 1 games. At least not for the BBC Micro, ZX Spectrum and Oric 1 that I tested with. I don't *think* that the C64 had graphics at this version either. There are some opcodes that in later version will allow it - I treat them as illegal here for the time being (much more has to happen to support v2+). Later ones support "lines + flood fill" and then bitmap graphics.

I'm basing the C64 ones on this -> https://www.lemon64.com/games/list.php? ... 0computing I would love to know how I get a C64 ROM that isn't in a D64 file. I might have misunderstood the format but I cannot e.g. see the dictionary if I view a D64 file in a hex editor.

EDIT: actually they look like they may be two sides interleaved (maybe) which won't work...

And on that link, in '83 and '84 they look just to be text based. Happy to be corrected. My initial goal was to get this working on a command line, just supporting the BBC Micro. But it was pretty straightforward to make it generic across the other platforms. And then at some point I'll dual support a pop-up window that can support graphics in the later versions of A-Code.

I chose python because too because it's relatively straightforward to read (no pointers!) and hackable. It's also readily supported on many platforms so it should just work if you install Python 3.10+ and download the zip or git clone the repository. I hope so at least but I welcome any feedback/issues.

The code isn't perfect i.e. I'm sure I could have included some more defensive coding - but for moving to another language or technology I wanted it laid it out simply, which I think I achieved. I wrote it twice - once when I was unpicking the 6502 code and then again when I understand what it was trying to do. The second iteration is so much more understandable (it's no longer refactored 6502 code with copious notes on what zero page was doing at the time!). A MASSIVE part of understanding it was decompiling the Lords of Time A-Code and annotating it - I haven't finished that fully yet but I'll release hopefully in the next few weeks. It showed me what it was doing with the exit data and flags...
Last edited by melchett on Sun Jan 22, 2023 5:13 pm, edited 1 time in total.
melchett
Posts: 478
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by melchett »

lurkio wrote: Sun Jan 22, 2023 3:16 pm Good Lord! I’ve only just seen this, and I haven’t begun to digest any of it yet, but at first glance it looks absolutely monumental! Well done! Amazing work!

=D> =D> =D>

Of course, you know that the next step is for you to make an adventure creator utility that compiles a user-friendly adventure language down to A-code..! (A sort of “Quill for A-code”!)

:wink:
Yes I think we could make the input medium more modern rather than constrain to lots of brackets and shorthand as it would have had to be in the day. It's interesting seeing some of the build or code or whatever artifacts as "junk bytes" in memory.

And thank you for the early praise - it grew and grew and I just kept going.
fuzzel
Posts: 1191
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by fuzzel »

Absolutely fantastic work melchett. For text adventure fanatics like myself this puts you in the rarified company of the likes of Mark Moxon and the very mysterious Level 7. How long have we waited for someone with the capability and love of adventuring to do this? Of course, it also inspires me to attempt a disassembly myself, maybe of one of the Magus games, not sure I have the technical skills though. Like lurkio I'd love to see someone create an A-code development program to create adventures for the beeb, maybe a two or three roomer test game to begin with. I'd also like to see a disassembly of the two Level 9 adventures with graphics, Erik the Viking and Emerald Isle, to see how they crammed all those pictures in.
melchett
Posts: 478
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by melchett »

fuzzel wrote: Sun Jan 22, 2023 8:06 pm Absolutely fantastic work melchett. For text adventure fanatics like myself this puts you in the rarified company of the likes of Mark Moxon and the very mysterious Level 7. How long have we waited for someone with the capability and love of adventuring to do this? Of course, it also inspires me to attempt a disassembly myself, maybe of one of the Magus games, not sure I have the technical skills though. Like lurkio I'd love to see someone create an A-code development program to create adventures for the beeb, maybe a two or three roomer test game to begin with. I'd also like to see a disassembly of the two Level 9 adventures with graphics, Erik the Viking and Emerald Isle, to see how they crammed all those pictures in.
Thank you Fuzzel - I noticed a few comments I need to correct and make readable in the 6502 game engine code. There are a a few TODOs from when I started that I neglected to update, will address those tomorrow. Not quite sure it's on Mark Moxon's or Level 7's level but thank you. Always adored Level 9 adventures. And you work out the engine but then you have to work out the game that's running on it at the same. The A-Code is such a great abstraction but still seems a huge amount of effort to create for an adventure author. Love to see how they knew it'd fit in X amount of memory back in the day.

A creator is possible now (and maybe worthwhile even for v1) - I wonder if they developed a debugger too on a bigger computer for the A-Code. Writing, compiling and debugging without that would have been so difficult. It'd be nice to have say a JSON based specification for the game data with a UI that expands it - dictionary, messages, locations, exits, lists. All needs pulling together with a language that can reference each of those and a UI would be great for that.
neilh
Posts: 19
Joined: Fri Jan 20, 2023 11:56 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by neilh »

Just wanted to say this is great and I'm looking forward to getting some time to look through it all! I used to love the Level 9 games back in the day and remember spending quite a while tinkering with one of my own!

...school got in the way of it ever being more than a tinkering though!
melchett
Posts: 478
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by melchett »

neilh wrote: Mon Jan 23, 2023 2:19 pm Just wanted to say this is great and I'm looking forward to getting some time to look through it all! I used to love the Level 9 games back in the day and remember spending quite a while tinkering with one of my own!

...school got in the way of it ever being more than a tinkering though!
Thank you @neilh - me too which is what eventually led me to the disassembly / reassembly and the python interpreter. I was too young to tinker with anything at the time but was the adventures were sublime. Lords of Time was the hook for me, closely followed by Snowball when I figured out how to get out of the 6.8k location. I imagine there are about 7 people in the world who are interested in the github repository :D
User avatar
Lardo Boffin
Posts: 2977
Joined: Thu Aug 06, 2015 7:47 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by Lardo Boffin »

I’m one of them! Great stuff. :D
Adventure Language on GitHub
Atom, issue 5, YARRB + video noise killer
Elk
A number of econetted (is that a word?) Beebs
BBC Master, Datacentre + HDD, pi co-proc, econet, NULA
neilh
Posts: 19
Joined: Fri Jan 20, 2023 11:56 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by neilh »

melchett wrote: Mon Jan 23, 2023 11:13 pm Thank you @neilh - me too which is what eventually led me to the disassembly / reassembly and the python interpreter. I was too young to tinker with anything at the time but was the adventures were sublime. Lords of Time was the hook for me, closely followed by Snowball when I figured out how to get out of the 6.8k location. I imagine there are about 7 people in the world who are interested in the github repository :D
Well I'm happy to be one of the 7 - although I've a horrible feeling I'm now heading down a rabbit hole :?
User avatar
davidb
Posts: 3395
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by davidb »

I'm impressed by the amount of effort that must have gone into this project. Well done! :D

A while ago I started disassembling Red Moon and Dungeon Adventure to see if I could reassemble them to partly run from ROM on the Electron. It would be good to make the Level 9 adventures run on all the Acorn machines. :)
fuzzel
Posts: 1191
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by fuzzel »

This has got me thinking about playing Dungeon Adventure again. I've played and solved Colossal Adventure and Adventure Quest both back in the day and more recently and I love them dearly but I think Dungeon Adventure could potentially be the best of three (it's absolutely massive). I've never managed to play it to the end though and looking back I remember finding it rather tedious having to lug that packing case around so you can store stuff by going in, dropping or picking things up and then exiting again (there is, to be fair, a belt you can wear to increase your inventory limit). So my point is, is there a way to increase the inventory limit, say to 255, so I can play the three games more enjoyably without the tediousness of planning where to drop things for use later on? I've had a quick look in the github repository and have found the message "You can't carry any more." but wondered where the actual flag is (eg CMP#4 or perhaps there's a zero page location which holds the inventory limit instead eg CMP&71) that could be changed. Hopefully it's not within the a-code which I imagine would be more of a challenge to amend.
User avatar
scruss
Posts: 653
Joined: Sun Jul 01, 2018 4:12 pm
Location: Toronto
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by scruss »

Amazing work - thank you!
melchett wrote: Sun Jan 22, 2023 5:07 pm I'm basing the C64 ones on this -> https://www.lemon64.com/games/list.php? ... 0computing I would love to know how I get a C64 ROM that isn't in a D64 file. I might have misunderstood the format but I cannot e.g. see the dictionary if I view a D64 file in a hex editor.
It's a slightly fiddly format. The c1541 utility that comes with Vice can extract PRG files, but it has syntax I can never quite work out.

I have seen reports that the Level 9 disk games for the C64 may have had graphics, but the tape versions didn't. While I've found a few tape images of the games, extracting PRG files eludes me. The TAP/T64 formats for the C64 are very underused, and the tools to work with them old and no longer build for me.

I could find C64 people who could get the PRG files for you if you wish
melchett
Posts: 478
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by melchett »

melchett wrote: Sat Jan 28, 2023 10:47 pm Well I'm happy to be one of the 7 - although I've a horrible feeling I'm now heading down a rabbit hole :?
Made my day - thank you.
melchett
Posts: 478
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by melchett »

davidb wrote: Tue Jan 24, 2023 8:40 pm A while ago I started disassembling Red Moon and Dungeon Adventure to see if I could reassemble them to partly run from ROM on the Electron. It would be good to make the Level 9 adventures run on all the Acorn machines. :)
I think that should be achievable easily especially for the v1 / v2 games (latter I have "text only" working today, not committed/published yet). Happy to help with whatever your goal is here - I think Electron? Does sideways RAM work for an Electron? I imagine it does completely.
User avatar
davidb
Posts: 3395
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by davidb »

melchett wrote: Sat Jan 28, 2023 10:52 pm
davidb wrote: Tue Jan 24, 2023 8:40 pm A while ago I started disassembling Red Moon and Dungeon Adventure to see if I could reassemble them to partly run from ROM on the Electron. It would be good to make the Level 9 adventures run on all the Acorn machines. :)
I think that should be achievable easily especially for the v1 / v2 games (latter I have "text only" working today, not committed/published yet). Happy to help with whatever your goal is here - I think Electron? Does sideways RAM work for an Electron? I imagine it does completely.
It's been a while since I looked at them and I'm not sure if I even got to the point where I could reassemble the original binaries.
My original goal was to move all the code and static data into ROM and only use RAM for dynamic data, hoping to free up enough space to run either game in MODE 6.
neilh
Posts: 19
Joined: Fri Jan 20, 2023 11:56 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by neilh »

neilh wrote: Tue Jan 24, 2023 6:49 pm Well I'm happy to be one of the 7 - although I've a horrible feeling I'm now heading down a rabbit hole :?
Well I wasn't wrong - well and truly down a rabbit hole!

I thought I'd look at your notes, poke around in the code, play some of the old games and be happy... I've now wandered off into tweaking BeebDis, spent an age trying to cross-reference your notes with the downloads I had, got massively confused, decided to compare and disassemble several of them from scratch, got more confused why what I was seeing still didn't exactly match your notes...

...and I've now stumbled across what look like multiple releases of the games so I have a feeling I've been poking around in a different version to you...

Still, it's fun getting the brain cells going on some 6502 disassembly again - must be coming up to 40 years since I was doing that in anger :lol: :?
melchett
Posts: 478
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by melchett »

neilh wrote: Tue Jan 31, 2023 5:53 pm Well I wasn't wrong - well and truly down a rabbit hole!

I thought I'd look at your notes, poke around in the code, play some of the old games and be happy... I've now wandered off into tweaking BeebDis, spent an age trying to cross-reference your notes with the downloads I had, got massively confused, decided to compare and disassemble several of them from scratch, got more confused why what I was seeing still didn't exactly match your notes...

...and I've now stumbled across what look like multiple releases of the games so I have a feeling I've been poking around in a different version to you...

Still, it's fun getting the brain cells going on some 6502 disassembly again - must be coming up to 40 years since I was doing that in anger :lol: :?
Yes there are multiple versions, 4 in fact. I have version 2 working (text only so far) but I'm not happy with the code yet and have not documented it yet. Needs a little bit more time. Interestingly my version of Return to Eden has a bug in the A-Code when you choose an option on the big screen and blink at it. Spent hours trying to fix that on my engine before realising it wasn't my fault...

Version 2, has 3 extra commands and the compression is different - faster because each encoded string is separated by a byte that gives the number of encoded bytes that follow. I will write this up.

I am improving the comments too - some howling typos and grammar issues that will update some of at the weekend. That probably didn't help.

For disassembling, maybe better to use the ones you can compile from the github repository as the source. There are SO many different disk / tape versions where someone has added their own or move their own files tape to disk or added their own relocation part or deprotected a disk with differing results. For me, all I cared about was understanding how it worked, it didn't necessarily have to be the definitive version that I decompiled.

I would also say that BBC micro versions tend to be split into multiple files e.g. a loader with the exits embedded, that loads the main file or files and then lowers them in page. And then executes. Some I even found "BEEBSOFT" embedded in the game text - so maybe someone there wrote the tape to disk relocator. That one was a TOSEC version.

If you think there's something that can be improved in any part, let me know. I will re-read it all at some point. Either PM me or put it here.

I use BeebDis too - it's pretty good.
neilh
Posts: 19
Joined: Fri Jan 20, 2023 11:56 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by neilh »

melchett wrote: Wed Feb 01, 2023 5:10 pm I would also say that BBC micro versions tend to be split into multiple files e.g. a loader with the exits embedded, that loads the main file or files and then lowers them in page. And then executes. Some I even found "BEEBSOFT" embedded in the game text - so maybe someone there wrote the tape to disk relocator. That one was a TOSEC version.
There certainly seem to be a few that follow a pattern here, whether they are modified or not I don't know but I think I'm seeing some subtle differences in the engine code on them just to keep things interesting!

One thing I haven't seen documented is whether there are any markers to indicate the end of the A-code? It might be unnecessary because the engine/interpreters should never "fall off the end" but I'm wondering how you would go about dumping out just the A-code once you know where it starts #-o ...
melchett wrote: Wed Feb 01, 2023 5:10 pm I use BeebDis too - it's pretty good.
It certainly is - especially with a couple of tweaks/enhancements :wink:
neilh
Posts: 19
Joined: Fri Jan 20, 2023 11:56 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by neilh »

melchett wrote: Sun Jan 22, 2023 1:26 pm I captured all my notes (excuse any typos, I'll slowly improve that over time) here:

https://github.com/ajgbarnes/level9/blo ... ication.md
I don't have the ability to PM yet, but I have a few updates/corrections that I've made to a local copy of this. I think I've "shared" those with you via Github :roll:
(Github seems similar to but subtly different from CVS I used years ago so I'm hoping I've done it right! :mrgreen: )

Thanks again for your work on this =D>
melchett
Posts: 478
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by melchett »

neilh wrote: Fri Feb 10, 2023 1:33 pm I don't have the ability to PM yet, but I have a few updates/corrections that I've made to a local copy of this. I think I've "shared" those with you via Github :roll:
(Github seems similar to but subtly different from CVS I used years ago so I'm hoping I've done it right! :mrgreen: )

Thanks again for your work on this =D>
Oh excellent - I'm super pleased to see the pull request. I was building up the energy to pick through it again later this month. I go screenblind to it, having written it so I'm actually thrilled another pair of eyes has been through this so diligently.

I will go through the changes when I have some free time tomorrow (Saturday). Thank you, thank you, thank you!
neilh
Posts: 19
Joined: Fri Jan 20, 2023 11:56 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by neilh »

melchett wrote: Fri Feb 10, 2023 2:24 pm Oh excellent - I'm super pleased to see the pull request. I was building up the energy to pick through it again later this month. I go screenblind to it, having written it so I'm actually thrilled another pair of eyes has been through this so diligently.
You've put a lot of work into it and I'm enjoying tinkering with it! I thought I'd give you some feedback based on using your information to unpick both some of the a-code and some of your disassembled output.

Quite pleased so far to be able to generate this:

Code: Select all

0x0000 20 04 00 49 00 06 05 48 01 01 48 02 02 48 ff 03 ...I...H..H..H..
0x0010 09 01 04 a2 04 05 e3 04 05 e5 04 06 e1 04 06 0a ................
0x0020 01 04 7a 04 22 ee e1 04 06 0a 01 04 7a 04 6e f7 ..z.".......z.n.
0x0030 48 78 07 09 02 08 48 1e 09 09 02 0a 09 01 0b 48 Hx....H........H
0x0040 d8 0c 04 01 45 0c 09 01 0d 00 ed 03             ....E.......
which is an exact match for the start of the Colossal Adventure a-code - but compiled from:

Code: Select all

begin

	goto .start				//0x0000 (0x07e0): (0x00) Goto 0x0005
//**************************************************************************
	gotoa .0049				//0x0002 (0x07e2): (0x00) Goto 0x0049
//**************************************************************************
	.start
		clearworkspace			//0x0005 (0x07e5): (0x06) Function - Clear Workspace (0x05)
		$var01 = 0x01			//0x0007 (0x07e7): (0x08) Set var[0x01] = (constant) 0x01
		$var02 = 0x02			//0x000a (0x07ea): (0x08) Set var[0x02] = (constant) 0x02
		$var03 = 0xff			//0x000d (0x07ed): (0x08) Set var[0x03] = (constant) 0xff
		$var04 = $var01			//0x0010 (0x07f0): (0x09) Set var[0x04] = var[0x01]
	.loop
		$var05 = $list2[$var04]		//0x0013 (0x07f3): (0xa2) Set var[0x05] = list#2[var[0x04]] (list address 0x0795)
		$list3[$var04]=$var05		//0x0016 (0x07f6): (0xe3) Set list#3[var[0x04]] = var[0x05] (list address 0x0860)
		$list5[$var04]=$var06		//0x0019 (0x07f9): (0xe5) Set list#5[var[0x04]] = var[0x06] (list address 0x08b0)
		$list1[$var04]=$var06		//0x001c (0x07fc): (0xe1) Set list#1[var[0x04]] = var[0x06] (list address 0x07e0)
		$var04 += $var01		//0x001f (0x07ff): (0x0a) Set var[0x04] += var[0x01]
		if $var04 < 0x22 goto .loop	//0x0022 (0x0802): (0x1a) If var[0x04] < (constant) 0x22 then Goto 0x0013
	.loop2
		$list1[$var04] = $var06		//0x0026 (0x0806): (0xe1) Set list#1[var[0x04]] = var[0x06] (list address 0x07e0)
		$var04 += $var01		//0x0029 (0x0809): (0x0a) Set var[0x04] += var[0x01]
		if $var04 < 0x6e goto .loop2	//0x002c (0x080c): (0x1a) If var[0x04] < (constant) 0x6e then Goto 0x0026
		$var07 = 0x78			//0x0030 (0x0810): (0x08) Set var[0x07] = (constant) 0x78
		$var08 = $var02			//0x0033 (0x0813): (0x09) Set var[0x08] = var[0x02]
		$var09 = 0x1e			//0x0036 (0x0816): (0x08) Set var[0x09] = (constant) 0x1e
		$var0a = $var02			//0x0039 (0x0819): (0x09) Set var[0x0a] = var[0x02]
		$var0b = $var01			//0x003c (0x081c): (0x09) Set var[0x0b] = var[0x01]
		$var0c = 0xd8			//0x003f (0x081f): (0x08) Set var[0x0c] = (constant) 0xd8
		message $var01			//0x0042 (0x0822): (0x04) Print message var[0x01]
						// Print message  "\n "
		message $0c			//0x0044 (0x0824): (0x05) Print message (constant) 0x0c
		$var0d = $var01			//0x0046 (0x0826): (0x09) Set var[0x0d] = var[0x01]

	.0049
		gotoa 0x03ed			//0x0049 (0x0829): (0x00) Goto 0x03ed
end
Like I said earlier - I'm well down a rabbit hole :roll:
melchett
Posts: 478
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by melchett »

neilh wrote: Fri Feb 10, 2023 5:10 pm
You've put a lot of work into it and I'm enjoying tinkering with it! I thought I'd give you some feedback based on using your information to unpick both some of the a-code and some of your disassembled output.
Appreciate this enormously. Reviewed your review and it is committed now. The specification is much better for it.
neilh wrote: Fri Feb 10, 2023 5:10 pm Quite pleased so far to be able to generate this:

Code: Select all

0x0000 20 04 00 49 00 06 05 48 01 01 48 02 02 48 ff 03 ...I...H..H..H..
0x0010 09 01 04 a2 04 05 e3 04 05 e5 04 06 e1 04 06 0a ................
0x0020 01 04 7a 04 22 ee e1 04 06 0a 01 04 7a 04 6e f7 ..z.".......z.n.
0x0030 48 78 07 09 02 08 48 1e 09 09 02 0a 09 01 0b 48 Hx....H........H
0x0040 d8 0c 04 01 45 0c 09 01 0d 00 ed 03             ....E.......
Love it - and great to see. I have some insights into the compression routine for v1 too from some analysis I did. If I get some time I will write it up soon.
neilh wrote: Fri Feb 10, 2023 5:10 pm which is an exact match for the start of the Colossal Adventure a-code - but compiled from:

Code: Select all

begin

	goto .start				//0x0000 (0x07e0): (0x00) Goto 0x0005
//**************************************************************************
	gotoa .0049				//0x0002 (0x07e2): (0x00) Goto 0x0049
//**************************************************************************
	.start
		clearworkspace			//0x0005 (0x07e5): (0x06) Function - Clear Workspace (0x05)
		$var01 = 0x01			//0x0007 (0x07e7): (0x08) Set var[0x01] = (constant) 0x01
		$var02 = 0x02			//0x000a (0x07ea): (0x08) Set var[0x02] = (constant) 0x02
		$var03 = 0xff			//0x000d (0x07ed): (0x08) Set var[0x03] = (constant) 0xff
		$var04 = $var01			//0x0010 (0x07f0): (0x09) Set var[0x04] = var[0x01]
	.loop
		$var05 = $list2[$var04]		//0x0013 (0x07f3): (0xa2) Set var[0x05] = list#2[var[0x04]] (list address 0x0795)
		$list3[$var04]=$var05		//0x0016 (0x07f6): (0xe3) Set list#3[var[0x04]] = var[0x05] (list address 0x0860)
		$list5[$var04]=$var06		//0x0019 (0x07f9): (0xe5) Set list#5[var[0x04]] = var[0x06] (list address 0x08b0)
		$list1[$var04]=$var06		//0x001c (0x07fc): (0xe1) Set list#1[var[0x04]] = var[0x06] (list address 0x07e0)
		$var04 += $var01		//0x001f (0x07ff): (0x0a) Set var[0x04] += var[0x01]
		if $var04 < 0x22 goto .loop	//0x0022 (0x0802): (0x1a) If var[0x04] < (constant) 0x22 then Goto 0x0013
	.loop2
		$list1[$var04] = $var06		//0x0026 (0x0806): (0xe1) Set list#1[var[0x04]] = var[0x06] (list address 0x07e0)
		$var04 += $var01		//0x0029 (0x0809): (0x0a) Set var[0x04] += var[0x01]
		if $var04 < 0x6e goto .loop2	//0x002c (0x080c): (0x1a) If var[0x04] < (constant) 0x6e then Goto 0x0026
		$var07 = 0x78			//0x0030 (0x0810): (0x08) Set var[0x07] = (constant) 0x78
		$var08 = $var02			//0x0033 (0x0813): (0x09) Set var[0x08] = var[0x02]
		$var09 = 0x1e			//0x0036 (0x0816): (0x08) Set var[0x09] = (constant) 0x1e
		$var0a = $var02			//0x0039 (0x0819): (0x09) Set var[0x0a] = var[0x02]
		$var0b = $var01			//0x003c (0x081c): (0x09) Set var[0x0b] = var[0x01]
		$var0c = 0xd8			//0x003f (0x081f): (0x08) Set var[0x0c] = (constant) 0xd8
		message $var01			//0x0042 (0x0822): (0x04) Print message var[0x01]
						// Print message  "\n "
		message $0c			//0x0044 (0x0824): (0x05) Print message (constant) 0x0c
		$var0d = $var01			//0x0046 (0x0826): (0x09) Set var[0x0d] = var[0x01]

	.0049
		gotoa 0x03ed			//0x0049 (0x0829): (0x00) Goto 0x03ed
end
Like I said earlier - I'm well down a rabbit hole :roll:
That's lovely - I could not find anything in the source code that hinted at the "language" they used and we have an opportunity to make one based on modern day flexibiltiy I guess. I only found some BASIC fragments that they used to generate the code (I presume) but tiny tiny scraps. Great to see this so far and can't wait to see it evolve.

Many of those values that are set up at the beginning have meaning e.g. 0x00 is False, 0x01 is True, others represent where an object is e.g. being worn, in the inventory, destroyed or not yet in the game. Others,the location of the "clock" room in LoT, or the inventory limit. I have a list of them from Lords of Time and will add that to another markdown page soon (where they are not game rule specific). Seems consistent to a point across the v1 and v2 games I have seen so far. Many others are just game state e.g. "has the gladiator stolen the buckle yet" or what word / cmd / object ids matched the input words.
neilh
Posts: 19
Joined: Fri Jan 20, 2023 11:56 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by neilh »

Happy to contribute!
melchett wrote: Mon Feb 13, 2023 9:57 am That's lovely - I could not find anything in the source code that hinted at the "language" they used and we have an opportunity to make one based on modern day flexibiltiy I guess. I only found some BASIC fragments that they used to generate the code (I presume) but tiny tiny scraps. Great to see this so far and can't wait to see it evolve.
It'd be interesting to find out more about the tooling they used - this is mostly for fun and starting out with a language that aligns closely with the a-code. I'm thinking that once I have a functional compiler I can start to add "utility" parts to the language which can generate blocks of a-code automatically for you...
melchett wrote: Mon Feb 13, 2023 9:57 am Many of those values that are set up at the beginning have meaning e.g. 0x00 is False, 0x01 is True, others represent where an object is e.g. being worn, in the inventory, destroyed or not yet in the game. Others,the location of the "clock" room in LoT, or the inventory limit. I have a list of them from Lords of Time and will add that to another markdown page soon (where they are not game rule specific). Seems consistent to a point across the v1 and v2 games I have seen so far. Many others are just game state e.g. "has the gladiator stolen the buckle yet" or what word / cmd / object ids matched the input words.
Poking around in the a-code it certainly looked like certain variables or list positions were used for specific purposes. It would be great to get some insight into those - one feature I've added to the language at the moment is the ability to assign a specific variable number to a variable, so you could have "assign $clockRoom 0x01" for example if variable 1 is used to hold the clock room value. That allows the compilation to generate the same a-code as that in the game, but from a more readable format :)

...I'm part way through butchering your disassembly code to get it to generate output compatible with my compiler :lol:
neilh
Posts: 19
Joined: Fri Jan 20, 2023 11:56 am
Contact:

Re: Level 9 Version 1 Assembly + Python Interpreter

Post by neilh »

neilh wrote: Mon Feb 13, 2023 2:17 pm ...I'm part way through butchering your disassembly code to get it to generate output compatible with my compiler :lol:
After a bunch of head-scratching and staring at code I've got your decompiler generating output that can be (mostly) fed directly into my compiler and generated what looks like a byte-for-byte match for the Colossal Adventure a-code =D>

There were a couple of off-by-one errors in the decompiler which threw out some issues with labels, but then I also spent a lot of time trying to work out a couple of other areas that were just out by one byte... Turns out that in a couple of places the a-code uses an absolute reference for a branch that is actually within reach of being relative. My compiler was therefore generating a relative offset-based sequence which was 1 byte shorter than the actual a-code. Fortunately I'd added the ability to specify that a branch/jump should be forced to be absolute :roll:

...now to take a look at some of the others and see how I get on :)
Post Reply

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