8-Bit BTCS - 6502 Reverse Engineering Project

Any developer realated stuff
User avatar
Horpner
Posts: 224
Joined: Thu Jan 08, 2009 11:53 pm
Location: New England
Contact:

Post by Horpner »

Darendor wrote:Something as an aside, if you kill Mangar and his crew then teleport out of the level and back in and try to kill him again, the disk drive spins but nothing else happens.

I walked down to the mystery square after killing Mangar, and sure enough 2 Liches appeared. 1280 experience and 640 coins for a 6 member party...
The square promptly deleted itself after the fight.
Perhaps the liches exist for a party that tries to kill Mangar twice in one visit to the tower? ;)
Death and drek? WTF?
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

Horpner wrote:
Darendor wrote:Yup, the mystery square spawns 2 Liches for the party to fight after Mangar is dead.

However, the party isn't supposed to be able to trip the square in the first place because the door that the 3 shapes makes appear is one-way only, meaning that you can only teleport out from Mangar's antechamber.

I'll record a video and post it maybe.
Holy shiyot! I was starting to think the Liches where an urban legend. But now I'm wondering how in heck anybody ever found them before? Maybe hackers struck at some time in the past.
I dunno. Maybe Michael Cranford designed the lich square and forgot he made the door at 15N, 10E one-way only?

In any event, the video is: http://www.youtube.com/watch?v=7zt5jV3vo6A
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

Horpner wrote:
Darendor wrote:Something as an aside, if you kill Mangar and his crew then teleport out of the level and back in and try to kill him again, the disk drive spins but nothing else happens.

I walked down to the mystery square after killing Mangar, and sure enough 2 Liches appeared. 1280 experience and 640 coins for a 6 member party...
The square promptly deleted itself after the fight.
Perhaps the liches exist for a party that tries to kill Mangar twice in one visit to the tower? ;)
You cannot fight Mangar more than once, period. Even if you exit the tower and re-enter. There's apparently a global flag tripped once he's dead that doesn't reset until the system is switched off or something.
User avatar
Horpner
Posts: 224
Joined: Thu Jan 08, 2009 11:53 pm
Location: New England
Contact:

Post by Horpner »

Darendor wrote:
Horpner wrote:Perhaps the liches exist for a party that tries to kill Mangar twice in one visit to the tower? ;)
You cannot fight Mangar more than once, period. Even if you exit the tower and re-enter. There's apparently a global flag tripped once he's dead that doesn't reset until the system is switched off or something.
Right, but if you weren't cheating like we are, you'd probably try to farm Mangar by killing him, then teleporting down to level three, then making your way back up. And you'd run into the liches at that point. I'm sure that's what I must have done to meet up with them in the past, and how the rumor that they exist started.

So the 2 Liches kick your butt, and then you find out that Mangar's not even there any more. It's cruel and awesome. Too bad it crashes the Amiga.
Death and drek? WTF?
User avatar
Horpner
Posts: 224
Joined: Thu Jan 08, 2009 11:53 pm
Location: New England
Contact:

Post by Horpner »

Darendor wrote:I dunno. Maybe Michael Cranford designed the lich square and forgot he made the door at 15N, 10E one-way only?

In any event, the video is: http://www.youtube.com/watch?v=7zt5jV3vo6A
That was awesome.

>LICHES!!!!

:lol:
Death and drek? WTF?
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

So, this is what we've found:

- each special that runs the disk drive is loading a file: "NMXX.PRG"; true or false?
- When the player trips a special, it looks at a memory location for that special. I'm still not crystal clear on this bit.

Consider the teleporter/magic mouth on level 1 of Mangar's Tower that takes you to level 2. This is the sequence I'm imagining:

- I am closing in on 13N, 20E, seeing "Something special is near...".
- I step onto 13N, 20E. The game has a special here.
- It loads from the drive. The game displays "Magic mouth" in the caption box and loads the picture of the mouth on the wall.
- Then it clears the text window and displays: "A magic mout on the wall speaks to you, saying this: 'Perseverence in all things. (Press a key)'".
- Once a key is pressed, the party is teleported to 13N, 20E on level 2.

What files are loaded?
User avatar
Horpner
Posts: 224
Joined: Thu Jan 08, 2009 11:53 pm
Location: New England
Contact:

Post by Horpner »

Darendor wrote:So, this is what we've found:

- each special that runs the disk drive is loading a file: "NMXX.PRG"; true or false?
True. I modified my text-dumping program to pull all the text from every NMXX file. The dungeon specials start in file NM1F.PRG, the stairs that go a long way up, and run consecutively up to NM44.PRG, Mangar's Antechamber. But I've so far been unable to make sense of the file pointers contained in the dungeon data.

For example, the pointer for the NM1F.PRG program (the long stairway) is 10. This seems easy: just add f to the pointer. This works fine throughout the cellars. But in the catacombs, it stops working. Bashar Kalivor is in program NM23, so using our formula we expect the pointer say 14. But it doesn't--the pointer says 16. It's off by +2. In the Castle, things are again different. The old man's riddle on the second level is in NM2A. So the pointer should be 1B. But it's really 1c, off by -1.

I'm going to have to go through and notate them each with their file pointer, and maybe eventually it'll make sense.
- When the player trips a special, it looks at a memory location for that special. I'm still not crystal clear on this bit.
To simplify things as much as possible, let's consider a four-tile dungeon, with a correspondingly tiny memory map.

The map is stored at 00, and take up four bytes. Our map is just a square dungeon like this. It contains the stairs in with a welcome message, a dastardly anti-magic and darkness zone, 1 spinner, and a special that runs a program to award 500,000 xp to all your characters.

Code: Select all

+--+--+
|A/  @|
+     +
|^s s0|
+--+--+
Using lookup tables I posted elsewhere, we must encode the map at location 00. The map is stored from bottom left to top right, proceeding right and upwards.

That binary code for that map is 0100 0100 0001 0100 0100 0001 0001 0001, or, in hex:

00: 88 18 81 11

Next, there's the array of special features, one byte per tile. That's not enough to store every kind of feature you might like, but it does encode stairs, darkness, traps, portals, and treasure chests. Each feature is stored in one bit. Also, there's a flag set if something other than those features encoded here--these are all detected as "something special is near" by the SESI effect. The tiles are stored in the same order.

The first tile has stairs up and an "other special"--the welcome message. That sets bit 0 for the stairs up, and bit 2 for the special.

The second tile has just an "other special". So we set bit 2.

The top left tile has Anti-magic, which is also an "other special", and darkness, which we encode directly. So we set bit 2, for other, and bit 3 for darkness.

The top right tile has a spinner, and that's an "other special," too.

So our next four binary patterns look like this:

00000101 00000100 00001100 0000100

or in hex

04: 05 04 0b 04

So now we need somewhere to store which remaining special is which. The game uses a set of lists of coordinates so it can tell.

First, is a list of coordinates of special programs to pull from disk. This dungeon needs only one program, the one that awards bonus xp, but there are room for as many as four. The coordinates of that tile are 0N, 1E, so we get:

08: 00 01 ff ff ff ff ff ff

The remaining, empty, slots for programs are padded with ff.

Below that, we store the pointers to the programs on disk. For the sake of example, xp award is progam 1.

10: 01 ff ff ff ff ff ff ff

Next down is a list of the coordinates of Anti-magic zones. We have one at 1N, 0E.

18: 01 00 ff ff ff ff ff ff

Next down is the list of teleporters, and then a list of destinations. We don't have any of either.

20: ff ff ff ff ff ff ff ff
28: ff ff ff ff ff ff ff ff

Next down are the location of up to four spinners. We have one at 1N, 1E:

30: 01 01 ff ff ff ff ff ff

Next comes three empty tables for HP drains, SP recharge, and tiles where you get stuck.

38: ff ff ff ff ff ff ff ff
40: ff ff ff ff ff ff ff ff
48: ff ff ff ff ff ff ff ff

Next comes a list of message coordinates. We have a message at 0N, 0E.

50: 00 00 ff ff ff ff ff ff

Next comes a list of monster coordinates. We don't have any set monster encounters, so it's empty. Below it is a table of which monster is actually supposed to be encountered at the corresponding tile, and how many. But this is blank, too.

58: ff ff ff ff ff ff ff ff
60: ff ff ff ff ff ff ff ff

Finally, the special message text appears. We have just one message.

68: <some BTSCII text encoding a welcome message, terminated by dc>

So here's the whole dungeon, in roughly 120 bytes:

Code: Select all

00: 88 18 81 11 05 04 0b 04
08: 00 01 ff ff ff ff ff ff
10: 01 ff ff ff ff ff ff ff
18: 01 00 ff ff ff ff ff ff
20: ff ff ff ff ff ff ff ff
28: ff ff ff ff ff ff ff ff
30: 01 01 ff ff ff ff ff ff
38: ff ff ff ff ff ff ff ff
40: ff ff ff ff ff ff ff ff
48: ff ff ff ff ff ff ff ff
50: 00 00 ff ff ff ff ff ff
58: ff ff ff ff ff ff ff ff
60: ff ff ff ff ff ff ff ff
68: <some BTSCII text encoding a welcome message, terminated by dc>
As you walk around our little map, the game draws the screen and prevents you from walking through walls by looking at the 4 bytes at 00.
It also keeps track of the feature list at 04, so that SESI works right.

Let's say you just entered. The game checks location 04, the feature table, and sees there are stairs here, and a special.

On the C64, this means it first asks if you'd like to take the stairs out. If you don't, then it looks up the coordinates 0N, 0E in our little set of tables. It finds 00 00 at location 50, and knows this means it's a message. Since it's the first coordinate in the list, it looks up and prints the first message found at location 68.

Now you walk north. Oops! The game finds that the darkness flag is set, and turns out the light. It also sees the "other" flag, and so looks for 1N, 0E in the set of lists. It finds it in the memory location reserved for Anti-magic, and turns off all your spells.

So you quickly turn around, and go back south. You see the stairs and the welcome message again, and cast your spells again. Now you head east. When you walk here, the program sees that there's a special here (by checking the feature table), and looks up the coordinates in the set of tables. It finds them at 08, and knows this means it is to run a special program. Since this is the first coordinate, it looks up the first file pointer at 10, 01. So it runs NM01.PRG. Viola! You are 500,000 xp more awesome!
Death and drek? WTF?
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

That's incredible.

I will be applying the findings here into another program and testing it out soon. I think. Unless you want to?
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

Here's the latest version of my dungeon editor for you all to check out:
http://www.mediafire.com/?sharekey=2273 ... f6e8ebb871

The program name is "DUNGEONREADER.PRG". What this program does is load any dungeon map in the entire game you choose from the menu into memory for you to peruse.

As with the previous version, you cannot write to the disk so don't worry about ruining your dungeon disk.

Not all squares render properly yet; there's more POKEs to be inputted as I go along. But I wanted to display about 5 hours worth of work today.

Note: Getting Mangar's level 4 was very, very difficult.


Please post your feedback.
User avatar
Horpner
Posts: 224
Joined: Thu Jan 08, 2009 11:53 pm
Location: New England
Contact:

Post by Horpner »

Well, after that build-up I had to pull up Mangar's Tower level 4. It renders perfectly except for the secret doors.

The slowness of Basic is already quite apparent. However, it adds a special charm. I actually liked the way the characters got slowly corrupted as you loaded the dungeon--it was very old-school.

I can't imagine the amount of work that must have gone into scouring the disk for all this data. As soon as we can upgrade to reading the PRG files instead, then we can make rapid additional progress.

The dungeons are stored in the NMAX files, from 1 to F. NMA1, NMA2, etc. They are also in order from the first level of the cellars to the last level of Mangar's Tower.

I will try to take a look at the code this weekend and figure out a way to upgrade the system to read files instead of disk sectors. Weneed to keep all your sector-hunting work though, to be able to write the data back to disk without errors.
Death and drek? WTF?
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

Be advised that the currently uploaded version of DUNGEONREADER.PRG is dangerously close to generating an ?OUT OF MEMORY ERROR message.

Well, it's not actually close to BEING out of memory, but according to the Programmer's Reference Guide I had to put in line 90 with a pair of POKEs to prevent my BASIC program from overriding my character set.

To hell with it - stick a REM statement in front of those two POKEs at line 90 and suddenly I get 28,000 more bytes.

I would encourage you to go ahead and muck about with my program and make any changes you see fit. I redesigned it that way for my benefit as much as anyone else's so I can go "hmmm, the Wine Cellar loads up fine, how about the Sewers...ah! Secret door south, wall north and door east needs to be POKEd in..."...until I manage to finally get all possible combinations done.
Horpner wrote:Well, after that build-up I had to pull up Mangar's Tower level 4. It renders perfectly except for the secret doors.

The slowness of Basic is already quite apparent. However, it adds a special charm. I actually liked the way the characters got slowly corrupted as you loaded the dungeon--it was very old-school.

I can't imagine the amount of work that must have gone into scouring the disk for all this data. As soon as we can upgrade to reading the PRG files instead, then we can make rapid additional progress.

The dungeons are stored in the NMAX files, from 1 to F. NMA1, NMA2, etc. They are also in order from the first level of the cellars to the last level of Mangar's Tower.

I will try to take a look at the code this weekend and figure out a way to upgrade the system to read files instead of disk sectors. Weneed to keep all your sector-hunting work though, to be able to write the data back to disk without errors.
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

Well, I have at least 51 more characters to render into dungeon display codes and less than 200 bytes of memory left.

I need to consider redesigning the program in a couple of ways:

- Machine Language. You might as well ask me to invent a time machine. :?
- Using READ-DATA statements. I was going to do this anyways but I was waiting until I had all the characters converted first.

It looks like I'll be using screen shots of incomplete renders of each dungeon to extrapolate the data into a text file, then transferring the completed characters into the same text file, then going the READ-DATA route.

Oh well.
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

I'm completely and utterly unable to proceed with this right now.

Every time I try to sort through this, I get confused and pissed off.

Trying to get the dungeon tiles to translate properly and how to get it done without runninng out of memory.......


I'm open to suggestions, because I don't have the intelligence for this alone.
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

I think I need to convert the following line into a machine language subroutine:

Code: Select all

93 FORI=0TO2047:POKEI+12288,PEEK(I+53248):NEXTI
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

Alright, so, I started to poke around in some machine language and I successfully wrote my first ML program.

http://www.mediafire.com/?sharekey=2273 ... f6e8ebb871
Disk image is "PROJECT.D64" with "MLTYPER.PRG" as the file.

Load it, and type "SYS49152". The screen should turn black and clear itself.

Now, type anything and it'll display on the screen, and hit RETURN to exit.

Yeah, okay, big whoop, right? Well I figure if I could rewrite my dungeon reader in ML it might save some memory issues.

But first I need to confer with Horpner about the character issue.
Post Reply