It's raining Galbosses!

cmonkey

Active member
vacBacker
Feedback
4 (100%)
Credits
1,659CR
OK, so I found the random number generating function within Pac-Land and decided to have a bit of fun...


The routine itself is at $cdfa in the Bally-Midway version of the game and $cdea in the Namco (world) version. It's only 24 bytes in length. It's called during every vblank and then from a further 16 different points within the game code. Every time it's called it returns a random number in the range 0-$ff in register A. The random number isn't seeded with a random initial value so this means if you could actually manage to start two different games exactly the same number of vblanks after power-on the games would play identically.

The logic for the ghosts in the planes to decide whether to drop a baby ghost or a Galboss is :-

1) call the random number generator

2) if the result in register A is zero then call it again immediately, if not then drop a baby ghost

3) clear upper 7 bits of returned random number in register A

4) test bit 0 of A, if it's zero then drop a Galboss, if it's one then drop a baby ghost

So that means there's a 1 in 512 chance of a plane dropping a Galboss.

Of course with a bit of creating patching we can even the odds a little and make them drop a Galboss every time
smiley1.gif


I'm glad that I've figured out the random number generator function and all references to it, this means I can now well and truly figure out what is based on random numbers and what is based on other facts such as player score etc.
 

smarty

Ready Player One
vacBacker
Feedback
12 (100%)
Credits
1,305CR
More great work Adrian.

Seems like you're making good progress with understanding whats makes this game tick. Really interesting stuff, keep it up!
 

trm

Who loves you, and who do you love?
Feedback
2 (100%)
Credits
2,877CR
Nice work dude. What method do they use for calculating the random numbers? 24 bytes seems quite small and given the CPU something like MSM would be a bit slow.
 

trm

Who loves you, and who do you love?
Feedback
2 (100%)
Credits
2,877CR
Doh. Messed up my post. I'm not sure I follow the 1 in 512 chance of a galboss so I wondered if there was a typo in your post, or whether I misunderstood.

cmonkey said:
1) call the random number generator
2) if the result in register A is zero then call it again immediately, if not then drop a baby ghost
3) clear upper 7 bits of returned random number in register A
4) test bit 0 of A, if it's zero then drop a Galboss, if it's one then drop a baby ghost

My understanding of this is, if RNG <> 0 drop ghost. Then if RNG is even, drop galboss else drop ghost.

So it's 1 in 2 for a galboss which I'm guessing isn't true as I've never seen one in the game
smiley4.gif
Are steps 3 & 4 conditional on something else? I can see how you'd get a 1 in 512 that way.

Cheers
timtrm2013-09-04 12:08:53
 

cmonkey

Active member
vacBacker
Feedback
4 (100%)
Credits
1,659CR
The random number returned from the first call can be anything from 0-$ff so you've a 1 in 256 chance of getting a zero (assuming it truly is random). Then you've got a 1 in 2 chance of getting a 0 from bit zero of the second call to the random number generator. 256 * 2 = 512. I merely changed a conditional branch to a couple of nops for the first call and a conditional branch to an unconditional branch for the second one to force a constant rain of Galbosses.

The random number generating function isn't anything as fancy as the middle square method. I've never seen anything quite like it before to be honest. It goes like this :-

rnd: ldd $53 ; load D from contents of $2053 ($2053 into A and $2054 into B)

asla ; multiply A by 2

asla ; multiply A by 2

adda $53 ; add contents of $2053 to A

inca ; increment A

aslb ; multiply B by 2

bitb #$20 ; test bit 5 of B

bne .1 ; branch if it's set

bcc .2 ; branch if carry flag is clear

bra .3 ; branch always

.1: bcc .3 ; branch if carry flag is clear

.2: incb ; increment B

.3: std $53 ; store D at $2053 (A at $2053 and B at $2054)

adda $54 ; add contents of $2054 to A

rts

Contents of memory locations $2053 and $2054 are both zero on the first invocation of this routine.
 

Mitchell Gant

Active member
vacBacker
Feedback
2 (100%)
Credits
888CR
So if it were only called every VBLANK period it would not be very random at all, except to human eyes.

But you mentioned a further 16 points that it was called from, are any of these points specific to certain game states, that would in turn come from the players actions? For example does it get called when the jump button is pressed and the score ends in '000'.

That would make it much more 'truly' random right? Assuming we believe that we live in a 'random' universe and we don't get any proof of living in a simulated universe that is all deterministic...
smiley33.gif


Again, very interesting work you're doing there, like you're destined to disassemble Pac Land. Bravo!
smiley20.gif
 

frothmeister

Active member
vacBacker
Feedback
58 (100%)
Credits
938CR
You sure are on a mission with Pacland Adrian. Great stuff again!
smiley4.gif


One thing I've always wondered about this game that perhaps you may be able to answer is, what do the flowers signify? I know if you jump in certain places they appear but is there a point to this?

Do you have to reveal a certain number to get a bonus or anything?

Would be very interested to find out if you, or indeed anyone else knows the answer.
 

cmonkey

Active member
vacBacker
Feedback
4 (100%)
Credits
1,659CR
Give me a chance boys! I've not got that far yet! Reversing, and more importantly, fully understanding, code is a thankless, tiresome job, sometimes involving playing over the same part of the game again and again and again whilst observing multiple memory locations for minor changes. I'll get there eventually and share any secrets that I find with you guys. But until then you'll just have to be patient!
smiley17.gif


I intend to attack each of the other 16 call points for the random number generator but only via the structured approach that I'm currently using for the disassembly work. I don't want to deviate from following the flow of control of the game and start going off on a tangent.
 

frothmeister

Active member
vacBacker
Feedback
58 (100%)
Credits
938CR
cmonkey said:
Give me a chance boys! I've not got that far yet! Reversing, and more importantly, fully understanding, code is a thankless, tiresome job, sometimes involving playing over the same part of the game again and again and again whilst observing multiple memory locations for minor changes. I'll get there eventually and share any secrets that I find with you guys. But until then you'll just have to be patient!
smiley17.gif


I intend to attack each of the other 16 call points for the random number generator but only via the structured approach that I'm currently using for the disassembly work. I don't want to deviate from following the flow of control of the game and start going off on a tangent.

No worries dude, I completely understand your methodical approach, if you've got more exploration planned.

Just didn't know if it was something that was already common knowledge to anyone?

I do remember being told by my local arcade owners son something about them giving a bonus. Bear in mind though, this was 1984. I was 10 and he was 12 so more than likely taking out of his arse.
smiley36.gif
 
Top