8-Bit BTCS - Mangar's Special Event disassembled

Any developer realated stuff
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

8-Bit BTCS - Mangar's Special Event disassembled

Post by Darendor »

In case anyone out there is smart, I am hereby posting the disassembled code for the special event that loads when you battle Mangar (i.e. when you step onto the square).

The program loads into memory at location: $3B00
It stops at: $3B00 + $400 (whatever that equals, I hate hex) = $3F00 (I think)

Image

Now, this is what happens when the party steps onto the square:
- First, it checks to see if this special has been cleared (i.e. has the party already killed Mangar?)
-- Yes: Terminate special (end)
-- No: Proceed...
- Second, it loads the special, and the party has the option to fight or run. If the party runs, they are moved one square south and the special resets itself, waiting for the party to step onto the square again.
- If the party fights, the battle ensues. If at any point the party runs, see previous point.
- If the party wins, the special proceeds to the sequence with Kylearan congratulating, and so forth. The special then clears itself so that it can't be invoked again (also worth noting that once this special event clears itself, the event at 8N, 10E activates the Liches).

So, good luck to anyone who can decipher the ML code. :?
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

NB: Not every single ML instruction is an actual instruction; some of the "code" is tokens for text!

Bear in mind this table:
Note: cf is used for both captial "O" and zero.

c0=[unknown] c1=A c2=B c5=E c6=F c7=G c8=H cb=K cc=L cf=0/0 cd=M ce=N d0=P d2=R d3=S d4=T d9=Y
00=[CR]a0=_ a1=! a2=" a7=' a8=( a9=) ac=, ad=- ae=. ba=: bb=; b1=1 b5=5
e1=a e2=b e3=c e4=d e5=e e6=f e7=g e8=h e9=i ea=j eb=k
ec=l ed=m ee=n ef=o f0=p f2=r f3=s f4=t f5=u f6=v f7=w f8=x
f9=y bf=? db=[ dd=] ff=> bf=? bc=<

dc=[end]
User avatar
ZeroZero
Posts: 286
Joined: Tue Mar 10, 2009 9:10 pm
Location: Germany

As for the BT text encoding...

Post by ZeroZero »

... it seems that, starting with char A0, all text is encoded ASCII + 128, with two exceptions:
DC is text terminator and 00 is a carriage return. I haven't checked, if a "real" 0 is missing or included, but in some places Darendor found correctly, that the O is used as 0 as well.
User avatar
Twoflower
Posts: 128
Joined: Thu Mar 19, 2009 12:40 am
Location: Haarlem, NL
Contact:

Post by Twoflower »

Incase you haven't noticed allready, everything after 3C0A is either text or datatables, and the first 100 is valid code. Lot's of zeropages (adresses 00-FF) seems to be used, but it seems unlikely that variables such as "Mangar defeated or not" is stored there.

It might be interesting to find out what the variables at 03B0-03C0 does, and also what purpose the routines around 0800 and BC00-C000 has. It seems to be loading adresses (fex. BEAA, BC9B, BC0A, BC9B) in the accumulators X and Y and then jumping to the subroutine at f.ex 0809.
/Twoflower
User avatar
ZeroZero
Posts: 286
Joined: Tue Mar 10, 2009 9:10 pm
Location: Germany

Post by ZeroZero »

Thats why I assume it to be sorta "script language", like:

load value, jsr 803 (maybe "output text")
load value, jsr 806 (prolly "load image")
load value, jsr 809 (prolly "get key")

of course that subroutines are *NOT* what I commented above, just an assumption how the events could work. It seems they all end with a JMP back into the main proggy somewhere in the $A000s
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

3c07 is apparently the last ML instruction.
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

The exact text contained between $3c0a and $3eb2 in memory for this special event:
{3c0a}
You stand in the antechamber of Mangar the Dark, evil Archmage of Skara Brae. Mangar glares at you with deep hatred.
"Die, mortals!" he screams.~[cr][cr]With a wave of his hand a few of his close friends drop by. They don't look like
a fun group.[cr][cr](Press a key)~Kylearan, the good Archmage, appears before you in a flash of light. "Well done!" he
cries, beaming. "Your quest in Skara Brae is now finished.!"[cr][cr](Press a key)~[cr][cr]"The evil one is now defeated,
and his spell of winter will soon end."[cr][cr](Press a key)~[cr][cr]"You will all, as a symbol of my gratitude, receive
a gold and experience bonus of 300,000 units. Fare well and live long!"[cr][cr](Press a key)~[cr][cr]Kylear vanishes.~
Mangar!~Kylearan~{3eb2}
A total of 8 text messages. The "Mangar!" and "Kylearan" (the last two) are caption displays, when each NPC's picture is displayed in the window.

Anyone know where the JSR is that waits for the player to hit a key? Or for that matter, where it awards the party the 300,000 bonus?
User avatar
Twoflower
Posts: 128
Joined: Thu Mar 19, 2009 12:40 am
Location: Haarlem, NL
Contact:

Post by Twoflower »

Darendor:

Could you make a "save state" in VICE on the step prior to attacking Mangar and include the dungeon .D64 which you are running it from (for access to the character-data)? This would make it easier to test the different combinations, zero out routines and find out where the variable "Mangar defeated" is stored and so on.

I would also recommend you to add an Action Replay cartridge to your VICE setup. This would give you the benefit of not having to use the VICE-monitor for checking code or messages in the memory. It will also allow you to save and load files to and from whatever area you wish in the memory of the C-64. Believe me - a C-64 without cartridge is truly limiting. :-)

Secondly, I would like to recommend that you check out Triangles crack of the original Bard's Tale I. The main program files are linked together in this version, and the files on side A are decloaked. This also enables the cartridges turbo-loader which speeds things up quite a bit.
/Twoflower
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

Twoflower wrote:Darendor:

Could you make a "save state" in VICE on the step prior to attacking Mangar and include the dungeon .D64 which you are running it from (for access to the character-data)? This would make it easier to test the different combinations, zero out routines and find out where the variable "Mangar defeated" is stored and so on.

I would also recommend you to add an Action Replay cartridge to your VICE setup. This would give you the benefit of not having to use the VICE-monitor for checking code or messages in the memory. It will also allow you to save and load files to and from whatever area you wish in the memory of the C-64. Believe me - a C-64 without cartridge is truly limiting. :-)

Secondly, I would like to recommend that you check out Triangles crack of the original Bard's Tale I. The main program files are linked together in this version, and the files on side A are decloaked. This also enables the cartridges turbo-loader which speeds things up quite a bit.
:?
User avatar
Twoflower
Posts: 128
Joined: Thu Mar 19, 2009 12:40 am
Location: Haarlem, NL
Contact:

Post by Twoflower »

Oh. I might have overcomplicated things above - all that is needed to do is really to go into the "Snapshot" menu, choose "Save snapshot image..." and click the radiobutton "Save currently attached diskimages". :-)

The rest was just a couple of recommendations for making interaction with the game easier. I didn't mean to startle you up with some over-complicated things.
/Twoflower
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

Thanks for the recommendations.

Are you able to make any further sense of the code I've posted?
User avatar
Twoflower
Posts: 128
Joined: Thu Mar 19, 2009 12:40 am
Location: Haarlem, NL
Contact:

Post by Twoflower »

Yep, investigating the $0800 subroutines now from The Guild.

As it seems, $0809 is definitly a "plot text" routine. You enter the startvalue in Y and X and jump to the routine (f.ex LDY#$B9, LDX#$98, JSR$0809). $080F seems to invoke the "press-any-key-routine". ZeroZero seems to be right about this beeing a script-language built up by small snippets of code directing it.

On $B998 in The Guild we find the text "Press Any Key...". :-)
/Twoflower
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

Twoflower wrote:Yep, investigating the $0800 subroutines now from The Guild.

As it seems, $0809 is definitly a "plot text" routine. You enter the startvalue in Y and X and jump to the routine (f.ex LDY#$B9, LDX#$98, JSR$0809). $080F seems to invoke the "press-any-key-routine". ZeroZero seems to be right about this beeing a script-language built up by small snippets of code directing it.

On $B998 in The Guild we find the text "Press Any Key...". :-)
So...Y has the high byte, X has the low byte, and $0809 is the routine that jumps to the Y+X address. Or something.

Machine language hurts my head. :?
User avatar
Twoflower
Posts: 128
Joined: Thu Mar 19, 2009 12:40 am
Location: Haarlem, NL
Contact:

Post by Twoflower »

Heh. It seems to be possible to invoke some of the special events just by loading them and calling them. I just picked a fight with Mangar and his horde right outside The Guild. As it seems, $FE may actually be the check-up byte for whether or not the Mangar event will be triggered.

Starting the routine at $3B00 will do the check, load the image of Mangar, wait for a keypress and then run the battle.
Starting the routine at $3B32 will bring you into the pre-combat screen. The following values determines the combat:

* Value at 03B0 (=enemy type 1 = Greater Demon / $6F)
* Value at 03B1 (=enemy type 2 = Vampire Lords / $6E)
* Value at 03B2 (=enemy type 3 = Mangar / $76)

* Value at 03B8 (= enemy 1 amount = $02)
* Value at 03B9 (= enemy 2 amount = $03)
* Value at 03BA (= enemy 3 amount = $01)


If we haven't a complete monsterlist allready, this is quite an easy way to test it out.

- All in all there seems to be $80 different monstertypes. ($00-$7F)
- Adding values above $80 loops the monstertable from the beginning.
Last edited by Twoflower on Tue Mar 24, 2009 2:47 pm, edited 1 time in total.
/Twoflower
User avatar
Twoflower
Posts: 128
Joined: Thu Mar 19, 2009 12:40 am
Location: Haarlem, NL
Contact:

Post by Twoflower »

Darendor wrote:So...Y has the high byte, X has the low byte, and $0809 is the routine that jumps to the Y+X address. Or something.

Machine language hurts my head. :?
Almost. :-)

* Y has the highbyte
* X has the lowbyte
* Together they determine from what address they should fetch the text which the routine at $0809 will be printing.

F.ex - LDY#$B9, LDX#$98, JSR$0809, JSR$080F = Get text starting from $B998 and run the print routine (=routine at $0809).
It will stop printing when it reaches an end-marker and then wait for a keypress (=routine at $080F).
/Twoflower
Post Reply