Mega Man X (as well as MMX2-MMX6, MM7 and Rockman & Forte) use the following code for its RNG (the addresses may be different depending on game):
809a7f  jsl $849086    [849086]  A:0000
849086  php                      A:0000
849087  rep #$20                 A:0000
849089  lda $0ba6      [860ba6]  A:0000
84908c  asl                      A:4cfa
84908d  clc                      A:99f4
84908e  adc $0ba6      [860ba6]  A:99f4
849091  xba                      A:e6ee
849092  sep #$20                 A:eee6
849094  sta $0ba7      [860ba7]  A:eee6
849097  clc                      A:eee6
849098  adc $0ba6      [860ba6]  A:eee6
84909b  sta $0ba6      [860ba6]  A:eee0
84909e  plp                      A:eee0
84909f  rtl                      A:eee0
In pseudocode, this would be the following function:
local function nextrng(rng)
	local rngh=(math.floor(rng*3/256))%256
	local rngl=(rngh+rng)%256
	rng=rngh*256+rngl
	return rng
end
The MMX RNG is a 16-bit period-43534 RNG starting with the value 0xD37 and using the above function. The following Lua script may be used to monitor and/or disassemble aspects of the RNG and how it is used:
In MMX-MMX3, the game auto-calls the RNG routine once per frame (usually) without using its value. So if a frame cycles the RNG more than once, then the RNG was used for something important. Note: The auto-call always occurs during the frame first before any other RNG calls. The documentation below will not make reference to this auto-call (i.e. "first RNG value" refers to the first RNG call after the auto-call).
Dragging down a wall to create dust sprites will run the RNG once per dust sprite.

Mavericks

Chill Penguin

There are 6 Chill Penguin actions, assigned even numbers from 0 to 10 (according to RAM address 0xE6A):
0 - shoot four ice cubes
2 - jump to center and create a blizzard
4 - slide on the ground (invincible)
6 - jump at player
8 - create ice penguins
10 - stunned from an attack
Chill Penguin starts with action 0 (shoot four ice cubes). Otherwise, the next action is determined from the previous action and RNG value mod 16, based on a transition table (located at 0x86C45E in Rockman X (J) ROM):
         RNG value mod 16 (in hex)        
prev     0 1 2 3 4 5 6 7 8 9 A B C D E F
action   -------------------------------
0 or 10  0 2 2 4 4 4 4 4 4 4 6 6 8 8 8 8
2        0 0 2 4 4 6 6 6 6 6 6 6 8 8 8 8
4        0 0 0 0 2 2 4 6 6 8 8 8 8 8 8 8
6        0 0 0 0 0 0 0 2 2 2 2 4 4 6 8 8
8        0 0 0 0 2 2 2 2 2 2 2 4 4 6 6 8
There is one exception: If there are already ice penguins on the field (not destroyed), action 8 (create ice penguins) becomes action 0 (shoot ice cubes) instead.
Note that previous action being 10 (which is likely during a TAS) is treated the same as previous action being 0. Normally there is only 1/16 chance of going from action 0 to action 0, but if Chill Penguin is made to create ice penguins, the probability of action 0 -> action 0 goes up to 5/16.

Storm Eagle

Storm Eagle's possible actions are (numbers based on value in RAM address 0xE6A):
0 - blow wind
2 - dive at player
4 - shoot a storm tornado
6 - spit an egg
Storm Eagle starts with action 0 (blow wind). Otherwise, the next action is determined from the previous action and RNG value mod 32, based on a transition table (located at 0x86D41E in Rockman X (J) ROM). This table works differently than the one for Chill Penguin.
Note: Since the table works differently, the ranges given in the able are "upside down". The table lists the range of (RNG mod 32) that result in the next action. It is not possible to go from 4->4.
           new action
prev         0     2     4     6   
action     ------------------------
0          30-31 14-29 10-13  0-9   
2          28-31 26-27 16-25  0-15   
4          16-31  6-15   x    0-5   
6          22-31 18-21  2-17  0-1   
Exception: If Storm Eagle's next action is 0 or 4, but cannot land (due to action 2 causing Eagle to appear at the far left or right of the boss arena), the RNG value is rolled again until the action is 2 or 6.
Two other things are determined by RNG:
1) Wind duration (action 0)
One frame after deciding action 0, RNG value mod 4 is used to determine the duration of wind (RAM address 0xE9C):
0 (mod 4): 120 frames of wind
1 or 3 (mod 4): 240 frames of wind
2 (mod 4): 360 frames of wind
2) Number and direction of dives (action 2)
One frame after deciding action 2, one or two RNG values are called to determine the number of times Storm Eagle dives at the player (RAM address 0xE9E):
The 1st RNG value mod 16 determines whether the dive count is 1, or 6-9:
0 to 3 (mod 16): dive count = 1
4 to 15 (mod 16): dive count = 6 to 9
If the dive count is 6 to 9, a 2nd RNG value is called to determine the dive count:
dive count = (RNG mod 4) + 6
Right before each dive occurs, RNG value mod 2 is used to determine the direction:
0 (mod 2): dive right-to-left
1 (mod 2): dive left-to-right

Armored Armadillo

Armored Armadillo only has two main actions 0 and 2 (and two other very specific actions 6 and 8):
0 - roll around
2 - shoot energy shots
4 - ?
6 - powering up (if blocking a charged shot)
8 - stunned by hit
RNG affects actions 0 and 2 as follows:
1) Whether to do action 0 or 2
Armadillo always starts the battle with action 0.
If Armadillo has just done action 0 twice consecutively or action 2 twice consecutively, he will always do the other action next, and no RNG is called. Actions 4-8 are not taken into account, only occurrences of actions 0 and 2.
Otherwise Armadillo's next action is determined by RNG mod 16, his pixel distance from the wall he is facing, and values at table 0x86c983:
           RNG value mod 16 (in hex)        
           0 1 2 3 4 5 6 7 8 9 A B C D E F
distance   -------------------------------
1-79px     2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2
80-127px   2 0 2 2 0 2 2 2 2 2 2 0 2 2 0 2
>=128px    2 0 0 2 2 2 0 2 0 2 2 0 0 2 2 2
2) When doing action 0, whether to stop rolling
Each time Armadillo hits a surface, at least 9 RNG values are consumed. However, on the first hit, as well as on any ground hit, an extra RNG value is called to determine whether to stop rolling.
For the first hit on a wall (Armadillo hits the wall horizontally and switches to diagonally), this RNG call is the last of 10 RNG calls. For all hits on the ground, this RNG call is the first of 10 RNG calls. In each case, the RNG value mod 16 is used to determine whether to stop rolling:
0 to 5 (mod 16): Stop rolling
6 to 15 (mod 16): Continue rolling
3) How many energy shots during action 2
One frame after action 2 is decided, RNG value mod 16 is used to determine the number of energy shots fired (address 0xE9E), based on a table at 0x86c973:
RNG mod 16 (hex) 0 1 2 3 4 5 6 7 8 9 A B C D E F
                 -------------------------------
# shots          4 5 4 3 4 5 4 3 4 5 4 3 4 5 4 5

Sting Chameleon

Chameleon has the following actions (0xE6A):
0 - drop down to the ground
2 - go into camouflage
4 - move while camouflaged (always follows 2)
6 - attach to the ceiling and shake the room
8 - tail shooting attack
10 - attack with tongue
12 - stunned by boomerang
The RNG determines the following:
1) Transition between actions.
If Sting Chameleon is on the ground (at the beginning of battle, after dropping down, or after being stunned by boomerang), the RNG value mod 16 determines whether to do action 6 or 8:
0 to 3 (mod 16): action 8
4 to 15 (mod 16): action 6
After action 8, and action 10 while on a wall, the RNG value mod 16 determines whether to drop down (action 0) or camouflage (action 2):
0 to 2 (action 8) / 0 to 7 (action 10): drop down (action 0)
3 to 15 (action 8) / 8 to 15 (action 10): camouflage (action 2)
After camouflaging (action 2), the RNG value mod 16 determines whether Chameleon will move towards a corner and use action 8, or move towards the player and use action 10:
0 to 5 (mod 16): action 8
6 to 15 (mod 16): action 10
Note that action 6 always leads into action 2 (camouflage), and the number of times Chameleon uses his tongue to attack, or whether he uses his tongue to attack while on the ground, are not determined by RNG, but only by how close the player is to Chameleon.
2) How long Chameleon shakes the room in action 6
Before Chameleon shakes the room, RNG value mod 128 is used to determine the duration of shaking:
Duration of room shaking in frames: (RNG mod 128) + 60
3) Whether to continue the tail shooting attack in action 8
After each tail shooting attack during action 8, RNG value mod 128 is called to determine whether to continue the attack, or to stop:
0 to 11 (mod 16): Continue the attack
12 to 15 (mod 16): Stop the attack
Note that there is a max of three such attacks, Chameleon will always stop after the third attack. However, the RNG value will still be called.
When Chameleon stops action 8, the RNG value determining the transition from action 8 to action 0 or 2 is called immediately afterward.

Spark Mandrill

Spark Mandrill has the following actions:
0 - electric ball attack
2 - hang on ceiling and drop on player
4 - charge at player with punch
6 - jump at player
10 - frozen by shotgun ice
The RNG determines the following two things:
1) Initial action
At the beginning of battle, RNG mod 4 determines which of actions 0-6 Spark Mandrill should start out with:
0 (mod 4): action 0
1 (mod 4): action 2
2 (mod 4): action 4
3 (mod 4): action 6
2) Transition between actions
After each attack, Spark Mandrill's next action is determined from its previous action, RNG mod 32, and the following table (based on the table at 0x86cfde). The table is similar to the type used for Storm Eagle:
           new action
prev         0     2     4     6   
action     ------------------------
0          28-31 12-27  6-11  0-5  
2          26-31 22-25  6-21  0-5   
4          26-31 20-25 16-19  0-15  
6          16-31 10-15  4-9   0-3   
10         24-31 16-23  8-15  0-7

Launch Octopus

Launch Octopus has the following four actions:
0 - jump and fire torpedoes
2 - create a tornado
4 - fire homing fishes
6 - fire torpedoes (no jump)
The RNG determines the following two things:
1) Jump velocity (height) for action 0
When Launch Octopus jumps due to action 0, RNG value mod 4 is used to determine his initial upward jump velocity, in subunits (1/256 px) per frame. The values are from address 0x86c6f8:
0 (mod 4): 1222 subunits per frame (lowest)
1 (mod 4): 1365 subunits per frame
2 (mod 4): 1493 subunits per frame
3 (mod 4): 1611 subunits per frame (highest)
2) Transition between actions
Launch Octopus always starts battle with action 0.
Launch Octopus's next action is based on RNG value mod 32, as well as the distance from the wall he is facing, and whether his arms are cut off with Boomerang Cutter. The table is based on data from address 0x86c628:
(near = 0-79px, mid = 80-127px, far = 128px or more, * = arms are cut off)
         RNG value mod 32 (A=10, B=11, etc.)
         01234567 89ABCDEF GHIJKLMN OPQRSTUV
distance -----------------------------------
near     00000022 22444444 44444444 66666666
far      00000022 22222222 22224444 44666666
mid      00000000 00000022 22224444 44446666
near*    00000000 00066666 66666666 66666666
far*     00000000 00000066 66666666 66666666
mid*     00000000 00000000 00000666 66666666

Fortress Bosses

Bospider

There are three main Bospider actions determined by RNG:
1) Which wire Bospider appears on at the top of the screen (except at the very beginning)
The wire is determined by RNG value mod 4:
0 (mod 4): Appear on far right wire 
1 (mod 4): Appear on middle right wire
2 (mod 4): Appear on middle left wire
3 (mod 4): Appear on far left wire
2) Whether Bospider throws spiders while at the top of the screen.
Determined by RNG value mod 4:
0 (mod 4): Throw spiders
Otherwise: Don't throw spiders
(Note: Bospider throwing spiders while partway down the wires isn't determined by RNG, but by your relative vertical position. Staying below Bospider will prevent this action.)
3) The wires that appear
Determined by 8 RNG values (the game cycles 9 values, but the last value is not actually used). Wires are determined from bottom to top as follows:
1st RNG value mod 4 determines the position of the bottom wire:
0 or 3 (mod 4): Left 
1 (mod 4): Middle
2 (mod 4): Right
2nd-8th RNG values mod 2 determine the position of the next wire relative to the previous, in one of two directions (wires cannot repeat the previous position):
0 (mod 2): Left->Middle->Right->Left
1 (mod 2): Left->Right->Middle->Left

Rangda Bangda

Rangda Bangda actions are determined by RNG as follows:
1) The number of rounds of eye attacks before switching to the nose (closing the walls)
This is determined by RNG value mod 16 based on a table at address 0x86d4f7:
RNG mod 16 (hex)   0 1 2 3 4 5 6 7 8 9 A B C D E F
                   -------------------------------
# of rounds        1 2 3 1 2 3 1 2 2 3 2 3 2 2 3 2
This determination occurs at the very beginning of battle, and after the walls reopen after a nose attack. This is followed one frame later by the next part (determining the eye that attacks, and its action).
2) The particular eye that attacks, and its action
If both eyes are intact, there are four possible actions for each eye:
2 - attack with green eye (fire a single shot)
4 - attack with blue eye (fly out towards player's position)
6 - attack with red eye, flying out and shooting two shots in one of three particular formations
8 - attack with red eye, firing anywhere from one to four waves of triple shots
If one eye is destroyed, the other eye will always be red and use action 6 or 8.
a) If both eyes are intact:
Three RNG values are used to determine which eye attacks, and its action:
The 2nd RNG value mod 2 determines the eye that attacks:
0 (mod 2): Attack with left eye
1 (mod 2): Attack with right eye
Then the eye's action is determined by the 1st RNG value, as well as which eye it is, based on a table at 0x86d507. The algorithm uses floor(RNG value / 2) mod 16:
floor(RNG / 2) mod 16 (in hex):
                   0 1 2 3 4 5 6 7 8 9 A B C D E F
                   -------------------------------
left eye action    4 2 6 4 4 2 4 2 8 4 2 4 2 4 2 2
right eye action   2 4 4 2 8 4 2 4 4 2 4 2 4 6 4 2
The 3rd RNG value mod 4 determines the number of waves in action 8:
# of waves = (RNG mod 4) + 1
(Note that this RNG value is called even if the action is not 8; the value would be ignored in this case.)
If the action is 6: There is an additional RNG call later (around when the eye flies out of the wall) determining its formation. The formations are:
M - eye flies along a line towards the player, two shots on each side
L - eye flies along a line veering toward the left-hand side, two shots to its right-hand side
R - eye flies along a line veering toward the right-hand side, two shots to its left-hand side
The formation is determined based on a table at 0x86d53e. The algorithm uses floor(RNG value/4) mod 8:
floor(RNG / 4) mod 8:
            0 1 2 3 4 5 6 7
            ---------------
formation   M M R R L L R L
b) If one eye is destroyed:
There are 2 RNG calls. The remaining eye will always be red, with action 6 or 8 determined by the 1st RNG value mod 2:
0 (mod 2): action 6
1 (mod 2): action 8
As before, the 2nd RNG value determines the number of waves in action 8, and if the action is 6, there is an additional call later determining its formation, as specified in the previous part.
3) Nose action
There are two directions for nose movement, either start going up and to the left, or start going up and to the right. This is determined by RNG value mod 2:
0 (mod 2): Start going up and to the right
1 (mod 2): Start going up and to the left

GameResources/SNES/MegamanX/RNG last edited by FractalFusion 1 day ago
Page History Latest diff List referrers View Source