24.7%

Discussions and help for Bard's Tale I: Tales of the Unknown
Post Reply
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

24.7%

Post by Darendor »

In case anyone cared, I've figured out that on the C64 version of BTI, there is a 24.7% chance of getting into a random fight while walking the streets of Skara Brae.

Code: Select all

2f2b: dec $24
2f2d: bpl $2f33
2f2f: lda #$03
2f31: sta $24
2f33: jsr $0830  This does something sinister, I forget what...
2f36: jsr $0806  Clear the text screen...
2f39: ldy #$ae
2f3b: ldx #$fc
2f3d: jsr $0809  Print whatever is at $fcae...
2f40: lda $24
2f42: asl a   Math crap
2f43: tax     I refuse to file tax before April...
2f44: ldy $aef5,x   I think this loads into Y the contents of $aef5 plus X.
2f47: lda $aef4,x  I think this loads into A the contents of $aef4 plus X.
2f4a: tax   More tax
2f4b: jsr $0809  Print other text based on what aef4/aef5 pointed to...
24fe: inc $37
2f50: jsr $082a   Deploy the unicorns!
2f53: lda $5a     Grab randomly generated number from $5a into A
2f55: and #$3f   Don't forget to take the #$3f with you
2f57: bne $2f63  Break and enter at $2f63, or branch not equal to there
2f59: lda #$00   Zero the accumulator
2f5b: sta $e1    Set imminent combat mode to "monster"
2f5d: jsr $0893   Start a fight
2f60: jmp $ae0c  Exit routine
2f63: jmp $ae0c  Exit routine.  Because it was worth repeating.
So why do I think that means a 24.7% chance of encounters? Because if you take 3f and convert it to decimal, you get 63. The highest value that can be in $5a is FF, which is 255. The "and" operation at 2f57, from what I gather, means to divide 3f by ff, or 63/255, which comes out to be .247 something.

Otherwise known as 24.7%.

And now you know. Or at least, now I think I know and wanted to post how smart I may or may not be.
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

This was from file NM09.PRG on the CITY disk in case anyone wondered.
tpth
Posts: 128
Joined: Tue Feb 02, 2010 6:39 am

Post by tpth »

Huh. So it doesn't matter if you go through a door or not? I kinda always felt there was more chance of getting jumped on in a house, but this could be entirely imaginary.
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

Well, that might influence the percentage I guess.

I don't claim this to be conclusive, just something I thought was interesting.
drifting
Posts: 153
Joined: Wed Dec 07, 2011 10:21 pm

Re: 24.7%

Post by drifting »

Darendor wrote:So why do I think that means a 24.7% chance of encounters? Because if you take 3f and convert it to decimal, you get 63. The highest value that can be in $5a is FF, which is 255. The "and" operation at 2f57, from what I gather, means to divide 3f by ff, or 63/255, which comes out to be .247 something.
The "and" instruction isn't the same as divide. FF AND 3F does not equal FF DIV 3F. FF AND 3F equals 3F.

Code: Select all

2f55: and #$3f   Don't forget to take the #$3f with you
2f57: bne $2f63  Break and enter at $2f63, or branch not equal to there 
What these two lines of code are actually doing is checking that the lower 6 bits of the accumulator are not set. The AND instruction sets the Z flag if (in this case) A AND #$3F == 0. Which is only the case if the lower 6 bits are 0. The BNE instruction jumps to $2f63 if any of those lower 6 bits is set. This ends up being a 1 in 64 chance of a random encounter.
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

Well thank you.
Post Reply