Bwa-hahahaha!

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

Bwa-hahahaha!

Post by Horpner »

I believe I've successfully found where the current dungeon map is stored in memory on the C64 version of the game, and I've almost completely deciphered the format of the map data. It's very similar to what I was speculating.

When a dungeon is in memory, it's stored at $f800. There's one byte of data per dungeon square, so 482 bytes. The dungeon is mapped starting at 0N, 0E, and the rows go across to the east, with the more northern rows following.

This is for the map only. More work is needed for locating darkness, specials, stairs, traps, etc. The specials data seems to be located elsewhere in memory, though I have suspects, as before.

A simple plotting program could draw perfect BT maps of the walls, doors and secret doors using just the information I have now.

More details after lunch.
Death and drek? WTF?
User avatar
Horpner
Posts: 224
Joined: Thu Jan 08, 2009 11:53 pm
Location: New England
Contact:

Post by Horpner »

As I said above, there's one byte per map square. The byte is split into four two-bit fields, one for each cardinal direction, using the following encoding:

00 -> Nothing
01 -> Wall
10 -> Door
11 -> Secret Door

I have not verified the last one yet, but I will as soon as I study a map containing some known secret doors. There's nothing with that encoding in The Cellars of the Scarlet Bard.

The fields are stored in the following order: West, East, South, North.

The first room, 0N, 0E in The Cellars has a wall to the west and south, so its byte value is:

Code: Select all

W  E  S  N
01 00 01 00
4     4  (in hex)
The next byte in the data file is the square at 0N, 1E, and has a wall to the east and south.

Code: Select all

W  E  S  N
00 01 01 00
1     4  (in hex)
So the first two bytes of data at address $fb00 in memory are $4414.

You can see how the possibility of one-way doors and walls springs forth from this storage scheme.

Now I must decide what to do with this information.

Incidentally, I've verified that the map is stored verbatim on the dungeon disk--there's no compression used. Puzzle and hint texts are obfuscated though, even in memory. I guess MC didn't want anybody with a 64mon cartridge spoiling their fun.
Death and drek? WTF?
User avatar
Darendor
Posts: 1503
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

Go...to...my...thread in the BTCS area! :shock:
User avatar
Darendor
Posts: 1503
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

Horpner wrote:As I said above, there's one byte per map square. The byte is split into four two-bit fields, one for each cardinal direction, using the following encoding:

00 -> Nothing
01 -> Wall
10 -> Door
11 -> Secret Door

I have not verified the last one yet, but I will as soon as I study a map containing some known secret doors. There's nothing with that encoding in The Cellars of the Scarlet Bard.

The fields are stored in the following order: West, East, South, North.

The first room, 0N, 0E in The Cellars has a wall to the west and south, so its byte value is:

Code: Select all

W  E  S  N
01 00 01 00
4     4  (in hex)
The next byte in the data file is the square at 0N, 1E, and has a wall to the east and south.

Code: Select all

W  E  S  N
00 01 01 00
1     4  (in hex)
So the first two bytes of data at address $fb00 in memory are $4414.

You can see how the possibility of one-way doors and walls springs forth from this storage scheme.

Now I must decide what to do with this information.

Incidentally, I've verified that the map is stored verbatim on the dungeon disk--there's no compression used. Puzzle and hint texts are obfuscated though, even in memory. I guess MC didn't want anybody with a 64mon cartridge spoiling their fun.
Alright, so go to the Wine Cellar, face west, then pause your emulator by starting the ML monitor. Change the "W" byte to 10 (whatever it works out to be in hexadecimal) and exit the monitor and see if a door appears.
User avatar
dragonbait
Posts: 124
Joined: Tue May 15, 2007 12:21 am
Location: Under the Ruins of Yulash

Post by dragonbait »

drooling over the thought of a useful BT construction set. 8)
User avatar
Horpner
Posts: 224
Joined: Thu Jan 08, 2009 11:53 pm
Location: New England
Contact:

Post by Horpner »

Darendor wrote: Alright, so go to the Wine Cellar, face west, then pause your emulator by starting the ML monitor. Change the "W" byte to 10 (whatever it works out to be in hexadecimal) and exit the monitor and see if a door appears.
Using CCS64, I succeeded in creating a wall west from 0N, 1E in the cellars. It was one-way, of coures, because I didn't make a wall east of 0N, 0E.

This is powerful enough to allow us to enter any square in any dungeon. I don't know how portable the information will turn out to be, though.

It brings us a step closer to being able to design a dungeon that the original program could run. It just remains to be seen how hard it will be to compose our own specials.

I'll post in the BTCS forum when I'm finished learning as much as I can. I've found where stairs, traps, pre-set random encounters, and specials are flagged. Discovering how specials are stored is going to require some actual disassembling... I've managed to avoid it so far.

It might be more worth the effort to reverse engineer bt2 than this game, though.
Death and drek? WTF?
User avatar
Horpner
Posts: 224
Joined: Thu Jan 08, 2009 11:53 pm
Location: New England
Contact:

Post by Horpner »

I successfully modified a bt1 dungeon disk so that there's a secret door to the west from the first square of the cellars (and one back again--it wouldn't do to get stuck in there with a party without PHDO). Secret doors are indeed stored as the bit pattern "11".
Last edited by Horpner on Mon Jan 26, 2009 11:26 pm, edited 1 time in total.
Death and drek? WTF?
User avatar
Darendor
Posts: 1503
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

You managed to alter the dungeon code on disk?
User avatar
Horpner
Posts: 224
Joined: Thu Jan 08, 2009 11:53 pm
Location: New England
Contact:

Post by Horpner »

Yep. Well, a D64 disk image, anyhow.

Incidentally, it turns out that the secret door detection of, e.g., GRRE, doesn't turn off if you replace that spell with something that doesn't normally detect secret doors, e.g., MAFL. That's gotta be a bug, although a pointless one.
Death and drek? WTF?
User avatar
Darendor
Posts: 1503
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

I agree that reverse-engineering BTII would be more worthwhile since it's a more advanced engine.

You do realize that there's "Odd..." square in BTII that disable the party's "eye" spell, meaning doors that are secret become hidden again and such?
User avatar
Darendor
Posts: 1503
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

Care to e-mail me your Dungeon disk that you've modified?
User avatar
Horpner
Posts: 224
Joined: Thu Jan 08, 2009 11:53 pm
Location: New England
Contact:

Post by Horpner »

No problem. It's just the same as a normal dungeon disk, except with a secret door west of the entry stairs in the cellar. Just PM me your email addy.
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 agree that reverse-engineering BTII would be more worthwhile since it's a more advanced engine.

You do realize that there's "Odd..." square in BTII that disable the party's "eye" spell, meaning doors that are secret become hidden again and such?
Yes, I hate those squares, too. There's a magic mouth that actually cancels the whole spell in the first level of Oscon's Fortress.
Death and drek? WTF?
User avatar
Darendor
Posts: 1503
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

I don't suppose you're willing to post the memory locations for all 484 squares then?
User avatar
Horpner
Posts: 224
Joined: Thu Jan 08, 2009 11:53 pm
Location: New England
Contact:

Post by Horpner »

They are one after the other, starting at $f800 (in memory).

22 bytes per row, with the southern-most row first.

The next row up is next, and so forth.

On the disk, they could be anywhere. I modified the .d64 image directly, so I don't know precisely which track and sector the first dungeon is stored on. I'll have time to find out tomorrow, though, and can let you know. However, I can tell you that the bytes are arranged just the same on the diskette.
Death and drek? WTF?
Post Reply